Do this as a list comprehension?

Marc 'BlackJack' Rintsch bj_666 at gmx.net
Fri Jun 6 05:34:56 EDT 2008


On Thu, 05 Jun 2008 23:56:40 -0700, dwahli wrote:

> On Jun 6, 8:44 am, "Terry Reedy" <tjre... at udel.edu> wrote:
>>
>> Of course, enumerate(iterable) is just a facade over zip(itertools.count(),
>> iterable)
> 
> So you could write:
> gen = (x for x in itertools.izip(itertools.count(8), [0, 1, 1, 1, 1,
> 1, 1, 2, 2, 3, 3]))
> print list(gen)

Useless use of a generator expression.  This:

gen = itertools.izip(itertools.count(8), [0, 1, 1, 1, 1, 1, 1, 2, 2, 3, 3])
print list(gen)

has the same effect without the intermediate generator that does nothing
but passing the items.

Ciao,
	Marc 'BlackJack' Rintsch



More information about the Python-list mailing list