Do this as a list comprehension?
dwahli at gmail.com
dwahli at gmail.com
Fri Jun 6 02:56:40 EDT 2008
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)
Using zip like you own example is the best option.
If you have a huge amount of data and only want to iterate over the
result, using a generator is probably better:
gen = (x for x in itertools.izip(itertools.count(8), [0, 1, 1, 1, 1,
1, 1, 2, 2, 3, 3]))
for i, j in gen:
... your code here ...
More information about the Python-list
mailing list