[英]Python: from list of tuples to dictionary of tuples
Say I have the following list of tuples:假设我有以下元组列表:
mylist=[(459301.5857207412, 443923.4365563169),
(462583.4152000006, 434743.87659999914),
(464196.387177011, 442931.247071933)]
How could I turn it into a dictionary of tuples, where the key is the index of each tuple in the list, and the elements of the tuple in the dict are the two elements between parentheses?我怎么能把它变成一个元组字典,其中键是列表中每个元组的索引,字典中元组的元素是括号之间的两个元素?
The intended outcome would be:预期的结果是:
mydict={0:(459301.5857207412, 443923.4365563169),
1:(462583.4152000006, 434743.87659999914),
2:(464196.387177011, 442931.247071933)}
您可以使用字典理解:
mydict = {k: v for k,v in enumerate(mylist)}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.