
Exercise for reference:
Please complete the code so that it prints out the expected output.
a = [1, 2, 3]
Answer:
a = [1, 2, 3]
for index, item in enumerate(a):
print("Item %s has index %s" % (item, index))
Explanation:
enumerate(a) creates an enumerate object which yields pairs of indexes and items. Then we iterate through that object print out the item-indexpairs in each iteration together with some other strings.