Python 如何将索引值作为密钥对附加到空字典中?

Python 如何将索引值作为密钥对附加到空字典中?,python,dictionary,iterator,key-value,Python,Dictionary,Iterator,Key Value,我有一个名为k_points的列表,其中包含元组[(2.429584911990176,0.5040720081303796),(3.39608990024489,9.114060958885277),(5.451196187915455,5.522005580434297)],我希望将其作为该字典的键值对中的值,并将其追加,而索引将是键值对。我该怎么做? 到目前为止,我已经: dict_self = {} k_points = [(2.429584911990176, 0.5040720081

我有一个名为k_points的列表,其中包含元组[(2.429584911990176,0.5040720081303796),(3.39608990024489,9.114060958885277),(5.451196187915455,5.522005580434297)],我希望将其作为该字典的键值对中的值,并将其追加,而索引将是键值对。我该怎么做? 到目前为止,我已经:

dict_self = {}
k_points = [(2.429584911990176, 0.5040720081303796), (3.396089990024489, 9.114060958885277), (5.451196187915455, 5.522005580434297)]

for points in k_points:
     dict_self.update({enumerate(k_points) : points})
然后我得到名单

{<enumerate object at 0x0000026C7A0B36C0>: (2.429584911990176, 0.5040720081303796), <enumerate object at 0x0000026C7A0B3678>: (3.396089990024489, 9.114060958885277), <enumerate object at 0x0000026C7A0B3630>: (5.451196187915455, 5.522005580434297)}
{:(2.429584911990176,0.5040720081303796),:(3.39608990024489,9.114060958885277),:(5.451196187915455,5.522005580434297)}

至少我得到了正确的值,但我没有得到索引号作为密钥对。我怎样才能解决这个问题?

你可以这样说:

for i, point in enumerate(k_points):
     dict_self[i] = point
或者仅仅使用听写理解:

dict_self = {i : point for i, point in enumerate(k_points)}
两者都产生:

 {0: (2.429584911990176, 0.5040720081303796),
 1: (3.396089990024489, 9.114060958885277),
 2: (5.451196187915455, 5.522005580434297)}

你是说下面的

d={}
对于范围内的i(len(k_点)):
d[i]=点[i]