Suggestion for impriving list comprehensions

Tim Peters tim.one at home.com
Thu Jul 26 23:39:10 EDT 2001


[Steven D. Majewski]
> ...
> [ But maybe the generator versions above are better.
>   I'm still getting used to this new stuff.
>   Sometimes the syntax seems a bit awkward.
>   I hope that this __future__ stuff is not cast in stone until
>   we've had time to see how it works.  ]

Nothing is frozen until at earliest the first 2.2 beta release; indeed,
generators may go away entirely before 2.2 final.

There's something at least a *little* off with the dance between generators
and iterators, but I'm not clear on exactly what and haven't had more time
to consider it.  Part of it seems to be that

    for x in whatever:

magically applies iter() to whatever under the covers (nothing off there),
but if "whatever" is a generator(-function), iter(whatever) is an error.

I don't know *why* that seems a little bit off, because it makes perfect
sense <wink>.  But play with it long enough and I wouldn't be surprised if
you thought so too.

if-so-it's-in-need-of-articulation-ly y'rs  - tim





More information about the Python-list mailing list