Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/331.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/18.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_Python 3.x_List - Fatal编程技术网

Python 是否使用另一个列表的索引值打印列表中的项目?

Python 是否使用另一个列表的索引值打印列表中的项目?,python,python-3.x,list,Python,Python 3.x,List,我有两个清单,一个是目的地,另一个是你需要去的地方的费用 例如,如果用户选择了“7500”,所有花费“7500”的地方都会显示出来。正如您在下面的代码中所看到的,“7500”重复了两次,因此我需要两个具有该价格的目的地 我已经有了找到所需点数的代码,但我不知道如何继续打印与这些点数对应的目的地 destinations = ["Toronto", "Winnipeg", "London", "Ottawa","Miami", "Edmonton"] pointCosts = [7500, 900

我有两个清单,一个是目的地,另一个是你需要去的地方的费用

例如,如果用户选择了
“7500”
,所有花费
“7500”
的地方都会显示出来。正如您在下面的代码中所看到的,
“7500”
重复了两次,因此我需要两个具有该价格的目的地

我已经有了找到所需点数的代码,但我不知道如何继续打印与这些点数对应的目的地

destinations = ["Toronto", "Winnipeg", "London", "Ottawa","Miami", "Edmonton"]
pointCosts = [7500, 9000, 11000, 7500, 9500, 9000]

def CheapPoint (pointCosts):
    lowest = [0]
    for x in pointCosts:
        if x < lowest:
            lowest = x
destinations=[“多伦多”、“温尼伯”、“伦敦”、“渥太华”、“迈阿密”、“埃德蒙顿”]
点成本=[7500,9000,11000,7500,9500,9000]
def CheapPoint(点成本):
最低=[0]
对于x英寸成本:
如果x<最低值:
最低=x
例如,对于输出,我希望如下所示:

积分:7500
城市:多伦多
城市:渥太华

到目前为止,我只获得积分,但我也想获得目的地,而且我不能使用任何内置函数


谢谢

您是否尝试过使用字典而不是两个单独的列表? e、 g:
locations={“多伦多”:7500,“温尼伯”:9000…}

points = 7500
for destination,pointCost in locations.items():
    if pointCost == points:
        print (destination)

然后,您可以遍历字典以提取键的聚合

您是否尝试使用字典而不是两个单独的列表?
score = 7500

example = [ x for x, y in zip(destinations, pointCosts) if y == score ]
e、 g:
locations={“多伦多”:7500,“温尼伯”:9000…}

points = 7500
for destination,pointCost in locations.items():
    if pointCost == points:
        print (destination)
然后,您可以遍历字典以提取密钥的聚合

score = 7500

example = [ x for x, y in zip(destinations, pointCosts) if y == score ]
输出

['Toronto', 'Ottawa']
可以通过print()函数在单独的行上打印:

print(*example, sep = '\n')
输出:

Toronto
Ottawa
输出

['Toronto', 'Ottawa']
可以通过print()函数在单独的行上打印:

print(*example, sep = '\n')
输出:

Toronto
Ottawa
[如果y==7500,则在zip(目的地,点成本)中打印x,y的(y,x)]

7500,“多伦多”

7500,“渥太华”

[如果y==7500,则在zip(目的地,点成本)中打印x,y的(y,x)]

7500,“多伦多”

7500,“渥太华”


您可以添加代码以获取积分吗?
zip
这两个列表,然后简单地
过滤它们或使用列表理解。
[城市对城市,邮政成本(目的地,点成本)如果代码中的成本最低,则不应使用
[0]
初始化(列表),但如果数字较大,例如,
lost=100000000
您可以添加代码以获取分数吗?
zip
两个列表,然后简单地
过滤它们或使用列表理解。
[城市对城市,zip中的成本(目的地,点成本)如果代码中的成本最低,则不应使用
[0]
初始化(列表),但如果数字很大,例如
lower=100000000
谢谢,这真的很有帮助。有没有方法可以将它们打印在单独的行上?谢谢,这真的很有帮助。有没有方法可以将它们打印在单独的行上?