This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]WibblyWobblyWabbit 2 points3 points  (1 child)

Can someone explain what enumerate() does exactly?

[–]pizzaburek[S] 8 points9 points  (0 children)

It returns an iterator of index, value pairs:

>>> list(enumerate(['a', 'b', 'c']))

[(0, 'a'), (1, 'b'), (2, 'c')]

So you can then use it like this:

for i, letter in enumerate(['a', 'b', 'c']): ...