It reminded me of the SQL double NOT EXISTS:
SELECT DISTINCT store_type
FROM stores
WHERE NOT EXISTS (
SELECT *
FROM cities
WHERE NOT EXISTS (
SELECT *
FROM cities_stores
WHERE cities_stores.city = cities.city
AND cities_stores.store_type = stores.store_type
)
);find the store_types such that at least one store of that type exists in at least one city?
this is probably nerd sniping :(
Exactly, it's a nested iteration: the rightmost loop is just nested within the leftmost loop, so it's iterating on `states[(s,letter)]` for each value (s) of `state`.
The weirdest part, to me, is around that: it's surrounded by some sort of manual reduction, which changes the current `state` content by iterating over `word`.
It most certainly is a double loop. I can understand how it seems confusing but once you look at what's going on it really isn't all that complicated. Sure the syntax is a little less clear (due to the list comprehension, I think Guido is probably cringing right now) but the logic is fairly straightforward.
> At first it looks just like a double loop. But then you notice the right-most for
> is taking the list to iterate over from its own body, > which is the iterator of the left-most for loop Well I don't get what's weird (or I'm actually missing something in the post), it actually IS a double loop. [0] says: So exp2, 3, 4 can each depend on the previous levels var1, 2, 3...I wrote something like that in a comment on SO[1]
[0] http://www.python.org/dev/peps/pep-0289/#the-details[1] http://stackoverflow.com/questions/1016997/generate-from-gen...