Python syntax in Lisp and Scheme

Hannu Kankaanp?? hanzspam at yahoo.com.au
Tue Oct 7 10:04:48 EDT 2003


Pascal Costanza <costanza at web.de> wrote in message news:<blu4q0$1568$1 at f1node01.rhrz.uni-bonn.de>...
> ...but this means that
> 
> collect = []
> for l in some_file_name
>    if some_property:
>        collect.append(l)
> 
> ...is another solution for the single collector case. Now we have two 
> ways to do it. Isn't this supposed to be a bad sign in the context of 
> Python? I am confused...

It's all about what's the "correct" way to do it. In this case, it
would be

collect = [l for l in some_file_name if some_property]

And this would be expanded to the for-loop form *only* if it is needed.
Of course I can do

x = 5
x += y

Or I can do

x = 5 + y

That's not breaking against Python's principles. The latter
way is the right way.

(surely there are many debatable cases of which is the right
way, but the principle is adhered to as often as possible.
That's the best one can ever have)




More information about the Python-list mailing list