开发者

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

开发者 https://www.devze.com 2023-03-19 02:46 出处:网络
What I came up with is: keys, values = zip(*[(key, value) for (key, value) in my_d开发者_开发问答ict.iteritems()])

What I came up with is:

keys, values = zip(*[(key, value) for (key, value) in my_d开发者_开发问答ict.iteritems()])

But I am not satisfied. What do the pythonistas say?


keys, values = zip(*d.items())


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

keys, values = my_dict.keys(), my_dict.values()
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号