+ 1

Find the third largest number in a list in python

need to find the third number in python without using function

28th May 2018, 9:47 AM
Harry Singh
Harry Singh - avatar
2 odpowiedzi
0
l=[5,8,2,9,4,10,7] print("3rd largest in",l,"is",sorted(l)[-3])
28th May 2018, 10:28 AM
Louis
Louis - avatar
+ 9
#If you are not allowed to use sort, try this. l=[5,8,2,9,4,10,7] for j in range(3): max=l[0] for i in l: if i>max: max=i if j==2: print(max) else: l.remove(max)
28th May 2018, 10:36 AM
Louis
Louis - avatar