enumerate() for dictionary in python

前端 未结 11 1214
走了就别回头了
走了就别回头了 2020-12-08 05:55

I know we use enumerate for iterating a list but I tried it in a dictionary and it didn\'t give an error.

CODE:

enumm = {0: 1, 1: 2, 2:          


        
11条回答
  •  再見小時候
    2020-12-08 06:31

    Just thought I'd add, if you'd like to enumerate over the index, key, and values of a dictionary, your for loop should look like this:

    for index, (key, value) in enumerate(your_dict.items()):
        print(index, key, value)
    

提交回复
热议问题