Is there a more elegant way for unpacking keys and values of a dictionary into two lists, without losing consistence?

后端 未结 2 1838
醉酒成梦
醉酒成梦 2020-12-09 10:39

What I came up with is:

keys, values = zip(*[(key, value) for (key, value) in my_dict.iteritems()])

But I am not satisfied. What do the pyt

相关标签:
2条回答
  • 2020-12-09 10:52
    keys, values = zip(*d.items())
    
    0 讨论(0)
  • 2020-12-09 11:05

    What about using my_dict.keys() and my_dict.values()?

    keys, values = my_dict.keys(), my_dict.values()
    
    0 讨论(0)
提交回复
热议问题