+ 2
What does 'enumerate' do?
a = [1,2,3] for x,y in enumerate(a,2): print(x,y) ''' 2 1 3 2 4 3 '''
2 odpowiedzi
+ 6
It adds an index to every element of your iterable. Default is 0.
So in a list ['a', 'b']
you would get the elements (0, 'a') and (1, 'b').
With the second argument you can set the starting point of the indexing.
This can for example be convenient when you need both index and element in a for loop.
for index, element in my_list:
....
+ 2
Thanks! HonFu