[英]Create a dictionary from one key and list of tuples
I have a list of tuples.我有一个元组列表。 For example:
例如:
L = [(334, 269, 461, 482), (182, 178, 307, 471),(336, 268, 466, 483), (183, 177, 304, 470)]
The length of the list sometimes changes, it is not constant but the key is the same (for example, u'person')列表的长度有时会发生变化,它不是恒定的但键是相同的(例如,u'person')
key = u'person'
I tried to create the dictionary from the key and list, Unfortunately, it took the first tuple only.我试图从键和列表创建字典,不幸的是,它只使用了第一个元组。 the output was:
输出是:
{u'person': (334, 269, 461, 482)}
Here, the value was as tuple but I would like the output will be:在这里,值是元组,但我希望输出是:
{u'person': [(334, 269, 461, 482), (182, 178, 307, 471),(336, 268, 466, 483), (183, 177, 304, 470)]}
Here, the value is list of tuples.这里,值是元组列表。
You can use:您可以使用:
new_dict = {u'person': L}
Output:输出:
{u'person': [(334, 269, 461, 482), (182, 178, 307, 471),(336, 268, 466, 483), (183, 177, 304, 470)]}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.