Python中dict的元组列表 [英] Tuple list from dict in Python
本文介绍了Python中dict的元组列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何从 dict 中获取键值元组的列表在Python中?
How can I obtain a list of key-value tuples from a dict in Python?
推荐答案
仅适用于Python 2.x(感谢Alex):
For Python 2.x only (thanks Alex):
yourdict = {}
# ...
items = yourdict.items()
请参见 http://docs.python.org/library/stdtypes.html #dict.items 了解详情.
仅适用于Python 3.x(摘自 Alex的答案):
For Python 3.x only (taken from Alex's answer):
yourdict = {}
# ...
items = list(yourdict.items())
这篇关于Python中dict的元组列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文