[英]How to store the values of two lists in a single dictionary where values of first list is a key and the values of second list are attributes?
road= []
distance=[]
i= input ('THE NUMBER OF NODES TO TEST')
for i in range(0,i):
a = input(' THE NODE NUMBER \n')
b= input ('ENTER NODE VALUE \n')
road.append(a)
distance.append(b)
print 'THE NODES AND RESPECTIVE VALUES ARE'
print "NODES: \t | \t VALUES:\n " ,words, distance
In above python sample code road and distance are two lists which will store the value input by the user. 在上面的python示例代码中,road和distance是两个列表,它们将存储用户输入的值。 Now I want to add those data in a dictionary where
road[0]:distance[0], road[1]: distance[1]
and so on. 现在,我想将这些数据添加到字典中,其中的字典是
road[0]:distance[0], road[1]: distance[1]
等。 ie The values inserted in the list 'road' and 'distance' should be included in a new dictionary say 'map'which is somehow like this map={"road":"distance"} 即插入列表“ road”和“ distance”中的值应包含在新字典中,例如“ map”,这有点像此map = {“ road”:“ distance”}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.