Pythonic infinite for loop?
Nobody
nobody at nowhere.com
Thu Apr 14 22:33:03 EDT 2011
On Fri, 15 Apr 2011 12:10:52 +1000, Chris Angelico wrote:
> One, is there a way to make an xrange object and leave the top off?
itertools.count()
> And two, can the entire thing be turned into a list comprehension or
> something? Generally any construct with a for loop that appends to a
> list is begging to become a list comp, but I can't see how to do that
> when the input comes from a dictionary.
The source of a list comprehension can be any iterable; it doesn't have to
be a list. So:
lst = [parse_kwdlist(dct[key]) for key in dct]
or:
lst = [parse_kwdlist(val) for val in dct.itervalues()]
More information about the Python-list
mailing list