给定一个列表:
lis = [37.21, 37.21, 37.2, 44, 44, 44, 101, 101]
提取第二大元素的简单方法是什么?
[44, 44, 44]
我的尝试
lis = [37.21, 37.21, 37.2, 44, 44, 44, 101, 101]
def sublist_of_second_largest(lis):
maxx=max(lis)
n=lis.count(maxx)
for i in range(n):
lis.remove(maxx)
maxx=max(lis)
n=lis.count(maxx)
out=[]
for i in range(n):
out.append(maxx)
return out
print(sublist_of_second_largest(lis))