[英]how to change list and tuple into dict in python?
how join tuple list a dict? 如何加入元组列出字典?
this is what i have: 这就是我所拥有的:
[('a','b'),('c','d'),('e','f')]
and this is what i want: 这就是我想要的:
{'a':'b','c':'d','e':'f'}
thanks! 谢谢!
Just pass the list into the dict
constructor. 只需将列表传递到
dict
构造函数中即可。 As they are tuples, it will know how to create the dictionary. 由于它们是元组,它将知道如何创建字典。
l = [('a','b'),('c','d'),('e','f')]
d = dict(l)
dict([('a','b'),('c','d'),('e','f')]
应该做
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.