Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/295.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 - Fatal编程技术网

Python 查找并显示姓名列表的最高记录

Python 查找并显示姓名列表的最高记录,python,Python,我是Python新手。 我的任务是编写一个Python程序来读取由人名和身高组成的名单 有没有关于编码以找出最高高度并显示记录的建议或想法 例如,最高高度为180,结果将显示Adam,180,我们可以使用operator.itemgetter import operator stats = {'Dave':179, 'Adam':180, 'Daniel': 170} max(stats.items(), key=operator.itemgetter(1)) 如果您有单独的列表: names

我是Python新手。 我的任务是编写一个Python程序来读取由人名和身高组成的名单

有没有关于编码以找出最高高度并显示记录的建议或想法


例如,最高高度为180,结果将显示Adam,180,我们可以使用operator.itemgetter

import operator
stats = {'Dave':179, 'Adam':180, 'Daniel': 170}
max(stats.items(), key=operator.itemgetter(1))

如果您有单独的列表:

names  =  ['alireza','sarah','maryam','muhammad']
heights = [180,172,178,182]
print(names[heights.index(max(heights))])
如果你想使用字典:

names = {'alireza':180,'sarah':172,'maryam':178,'muhammad':182}

max(names.keys(), key=names.get)
如果要使用二维列表:

names = [['alireza',180],['sarah',172],['maryam',178],['muhammad',182]]
heights = list(zip(*names))[1]
print(names[heights.index(max(heights))][0])

请向我们展示你的数据源你得到了任务,而不是我们。在你要求一个现成的解决方案之前,请试着自己去做。参见max函数,查看它的关键参数。请参阅operator.itemgetter。用谷歌搜索这些和实验,如果你自己尝试的话,你会学到更多:-。你应该做你自己的家庭作业。谢谢吉姆,这很有帮助:D汉克斯:D我以后会试试字典
names = [['alireza',180],['sarah',172],['maryam',178],['muhammad',182]]
heights = list(zip(*names))[1]
print(names[heights.index(max(heights))][0])