List get both index and value. 1

List get both index and value.

bb = ['one', 'two', 'three', 'infinity']

for ii, vv in enumerate(bb):
    print(ii, vv)

# 0 one
# 1 two
# 2 three
# 3 infinity

Here is what the above code is Doing:
1. The enumerate() function takes a list as an argument and returns an enumerate object.
2. The enumerate object is iterable and returns a tuple containing a count (from start which defaults to 0) and the values obtained from iterating over sequence.
3. The for loop then assigns the count and value to the variables ii and vv, respectively.

Similar Posts