'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')
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.
Solution 1:[1]
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)]}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Abhyuday Vaish |