On 9/16/07, Guido van Rossum <[EMAIL PROTECTED]> wrote:
> I think it's not so obvious that reversing the order is any better
> when you throw in some if clauses:
>
> [friend for city in cities if city.name != "Amsterdam" for friend in
> city.friends if friend.name != "Guido"]
>
> vs.
>
> [friend for friend in city.friends if friend.name != "Guido" for city
> in cities if city.name != "Amsterdam"]
>
> --Guido
>

I think that it's still better, at least if you add some newlines:

[friend
(Ok, we are talking about a list of friends. From where do these
friends come from?)
for friend in city.friends if friend.name != "Guido"
(Ah, they are all the friends in a city who aren't called Guido. What
about the city?)
for city in cities if city.name != "Amsterdam"]
(Ah, the city is every city which isn't Amsterdam.)

Versus:

[friend
(Ok, we are talking about a list of friends. From where do these
friends come from?)
for city in cities if city.name != "Amsterdam"
(What do cities which aren't Amsterdam have to do with my friend?)
for friend in city.friends if friend.name != "Guido"]
(Ah, we're talking about all the friends in those cities who aren't
called Guido. Let's have a look at the first line to remember what we
do with them... ah, yes, we just return them...)

Noam
_______________________________________________
Python-3000 mailing list
Python-3000@python.org
http://mail.python.org/mailman/listinfo/python-3000
Unsubscribe: 
http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com

Reply via email to