iterate over a list with access to index and value


# Define a new list using [] square brackets.
fruits = ['banana', 'apple', 'orange', 'lemon', 'lime',
          'strawberry', 'kiwi', 'peach', 'grape', 'pineapple', 'mango']

# iterate over a list with access to index and value
print('=== Iterate and print index and value of items in a list ===')
for key, val in enumerate(fruits):
    print(key, ":", val)
# output
=== Iterate and print index and value of items in a list ===
0 : banana
1 : apple
2 : orange
3 : lemon
4 : lime
5 : strawberry
6 : kiwi
7 : peach
8 : grape
9 : pineapple
10 : mango