Following is the help on how to enumerate dictionary in Python.
Let’s say this is my dictionary:
my_dictionary = {'Audi' : 1000, 'BMW' : 2000, 'Mercedes' : 3000}
Enumerating a dictionary
This is how to enumerate the dictionary in Python:
my_dictionary = {'Audi' : 1000, 'BMW' : 2000, 'Mercedes' : 3000} for i, (car, number) in enumerate(my_dictionary.items()): print("index: {}, car: {}, number: {}".format(i, car, number))
Enumerate is returning the tuple object and my_dictionary.items returns an iterator. To gether they are returning both an index and a tuple of a pair key and value.