Given a list:
lis = [37.21, 37.21, 37.2, 44, 44, 44, 101, 101]
What is a simple way to extract the second-largest elements?
[44, 44, 44]
My attempt
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))