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

Python [名称标记,标记表中的标记]的目的是什么

Python [名称标记,标记表中的标记]的目的是什么,python,list,Python,List,这是密码 marksheet = [] for _ in range(0,int(input())): marksheet.append([input(), float(input())]) second_highest = sorted(list(set([marks for name, marks in marksheet])))[1] print('\n'.join([a for a,b in sorted(marksheet) if b == second_highest

这是密码

marksheet = []

for _ in range(0,int(input())):

    marksheet.append([input(), float(input())])

second_highest = sorted(list(set([marks for name, marks in marksheet])))[1]

print('\n'.join([a for a,b in sorted(marksheet) if b == second_highest]))

[marks for name,marksheet中的marks]
不产生与marksheet相同的列表吗?因此,我们不能用第二高=排序(列表(集合(标记表))[1]得到相同的结果吗?

正如chepner所提到的,
标记表是一个列表列表(内部列表中的两个项目)

对于2的输入,
marksheet

marksheet = [['Mark' , 1.2 ], ['Sam', 2.0]]
现在,这个列表理解-->
[marks for name,marks in marksheet]
获取marksheet列表中的每个列表项,然后从每个元素中取出标记


因此,输出将是一个新的列表-->
[1.2,2.0]
,它与原始的
标记表
列表不同。

在这里,我将为所有没有经验的新程序员添加一个小贡献

行[marks for name,marksheet中的marks]需要读取为

-> marks----for----name, marks----in----marksheet
一开始,我也很困惑,因为我把它当作一本书来读

-> marks for name,----marks in marksheet
无论这听起来多么愚蠢,我必须承认我面临着这个问题。在盯着这条简单的线看了一会儿之后,它突然出现在我的脑海里,我改变了我的视角。
如果这个答案对任何人都有帮助,我将不胜感激。

marksheet
是一个包含两个项目的列表。列表理解仅从每个列表中提取第二项,即从
[[x1,y1],[x2,y2]]
[y1,y2]
。这在交互式解释器中很容易确认。
次高
表示您想要
反向=真