Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将两个元素结合到python中_Python_List_Dictionary_Combinations - Fatal编程技术网

将两个元素结合到python中

将两个元素结合到python中,python,list,dictionary,combinations,Python,List,Dictionary,Combinations,我有一个由数据创建的列表,称为stations=[] 打印为 ['france', 'england', 'germany', 'china', 'paris', 'sydney', 'gold coast', 'canberra', 'perth', 'melbourne'] 我还有另一个函数x,它在打印时打印 [0.0, 3043.004178666758, 21558.2996208357, 40246.748450913066, 40908.82213277263, 43786.05

我有一个由数据创建的列表,称为stations=[]

打印为

 ['france', 'england', 'germany', 'china', 'paris', 'sydney', 'gold coast', 'canberra', 'perth', 'melbourne']
我还有另一个函数x,它在打印时打印

[0.0, 3043.004178666758, 21558.2996208357, 40246.748450913066, 40908.82213277263, 43786.0579097594, 67781.1426515405, 79693.11338661514, 65046.35819797423, 92804.01912347642]
我有两个问题

首先)是否有一种方法将两者结合起来,即我可以打印一个新的列表或打印的函数

[france = 0.0, england = 3043.004, germany = 21558.2999] and so on

其次,我可以创建变量或列表或类似的东西,使france保持值=0.0,以便如果以后生成0.0,我可以调用france和france变量中的任何数据?

使用
dict
zip

>>> lis1 = ['france', 'england', 'germany', 'china', 'paris', 'sydney', 'gold coast', 'canberra', 'perth', 'melbourne']
>>> lis2 = [0.0, 3043.004178666758, 21558.2996208357, 40246.748450913066, 40908.82213277263, 43786.0579097594, 67781.1426515405, 79693.11338661514, 65046.35819797423, 92804.01912347642]
>>> dic = dict(zip(lis1,lis2))
>>> dic 
{'canberra': 79693.11338661514,
 'china': 40246.748450913066,
 'england': 3043.004178666758,
 'france': 0.0,
 'germany': 21558.2996208357,
 'gold coast': 67781.1426515405,
 'melbourne': 92804.01912347642,
 'paris': 40908.82213277263,
 'perth': 65046.35819797423,
 'sydney': 43786.0579097594}

# Fetching values
>>> dic['france']
0.0
>>> dic['sydney']
43786.0579097594
打印键和值:

>>> for k,v in dic.iteritems():
        # k points to the key, and v points to the value
        if v < distance:
            print k,"is less than", distance
        else:    
            print k,"is greater than or equal to",distance
...         
england is greater than or equal to 1000
canberra is greater than or equal to 1000
paris is greater than or equal to 1000
france is less than 1000
melbourne is greater than or equal to 1000
germany is greater than or equal to 1000
sydney is greater than or equal to 1000
china is greater than or equal to 1000
gold coast is greater than or equal to 1000
perth is greater than or equal to 1000
dic.iteritems()中的k,v的
>:
#k指向键,v指向值
如果v<距离:
打印k,“小于”,距离
其他:
打印k,“大于或等于”,距离
...         
英格兰大于或等于1000
堪培拉大于或等于1000
巴黎大于或等于1000
法国不到1000人
墨尔本大于或等于1000
德国大于或等于1000
悉尼大于或等于1000
中国大于等于1000
黄金海岸大于或等于1000
珀斯大于或等于1000

使用
dict
zip

>>> lis1 = ['france', 'england', 'germany', 'china', 'paris', 'sydney', 'gold coast', 'canberra', 'perth', 'melbourne']
>>> lis2 = [0.0, 3043.004178666758, 21558.2996208357, 40246.748450913066, 40908.82213277263, 43786.0579097594, 67781.1426515405, 79693.11338661514, 65046.35819797423, 92804.01912347642]
>>> dic = dict(zip(lis1,lis2))
>>> dic 
{'canberra': 79693.11338661514,
 'china': 40246.748450913066,
 'england': 3043.004178666758,
 'france': 0.0,
 'germany': 21558.2996208357,
 'gold coast': 67781.1426515405,
 'melbourne': 92804.01912347642,
 'paris': 40908.82213277263,
 'perth': 65046.35819797423,
 'sydney': 43786.0579097594}

# Fetching values
>>> dic['france']
0.0
>>> dic['sydney']
43786.0579097594
打印键和值:

>>> for k,v in dic.iteritems():
        # k points to the key, and v points to the value
        if v < distance:
            print k,"is less than", distance
        else:    
            print k,"is greater than or equal to",distance
...         
england is greater than or equal to 1000
canberra is greater than or equal to 1000
paris is greater than or equal to 1000
france is less than 1000
melbourne is greater than or equal to 1000
germany is greater than or equal to 1000
sydney is greater than or equal to 1000
china is greater than or equal to 1000
gold coast is greater than or equal to 1000
perth is greater than or equal to 1000
dic.iteritems()中的k,v的
>:
#k指向键,v指向值
如果v<距离:
打印k,“小于”,距离
其他:
打印k,“大于或等于”,距离
...         
英格兰大于或等于1000
堪培拉大于或等于1000
巴黎大于或等于1000
法国不到1000人
墨尔本大于或等于1000
德国大于或等于1000
悉尼大于或等于1000
中国大于等于1000
黄金海岸大于或等于1000
珀斯大于或等于1000

我将如何整体打印dic?是否可以像同时打印所有值一样one@user2430623使用
for
循环。我怎么会不理解for循环在这个上下文中的用法。@user2430623您想打印什么。所有键和值?是的,所有键和值都是我要打印的。此外,如果我的值为0.0,则稍后会在代码中显示,它是否会自动链接到France我将如何整体打印dic?是否可以像同时打印所有值一样one@user2430623使用
for
循环。我怎么会不理解for循环在这个上下文中的用法。@user2430623您想打印什么。所有键和值?是的,所有键和值都是我要打印的。另外,如果我有0.0的值出现在代码中,它会自动链接到法国吗