Enumerate Dictionary Iterating Key and Value [duplicate]
Given a dictionary d: d # {‘A’: 1, ‘B’: 2, ‘C’: 3, ‘D’: 4} You can use a tuple to unpack the key-value pairs in the for loop header. for i, (k, v) in enumerate(d.items()): print(i, k, v) # 0 A 1 # 1 B 2 # 2 C 3 # 3 D 4 To … Read more