Get name of dictionary

后端 未结 6 1709
感情败类
感情败类 2021-02-13 22:19

I find myself needing to iterate over a list made of dictionaries and I need, for every iteration, the name of which dictionary I\'m iterating on.

Here\'s an MWE (the co

6条回答
  •  粉色の甜心
    2021-02-13 22:36

    You should also consider adding a "name" key to each dictionary.

    The names would be:

    for dc in dict_list:
        # Insert command that should replace ???
        print 'The name of the dictionary is: ', dc['name']
    

提交回复
热议问题