how to find 2nd largest no. in python | Sololearn: Learn to code for FREE!
+ 2

how to find 2nd largest no. in python

4th Jan 2019, 9:17 PM
Shubham Yadav
Shubham Yadav - avatar
3 Answers
+ 4
l = [1, 2, 3, 4, ] print(sorted(l)[-2]) # 3
4th Jan 2019, 9:37 PM
Anna
Anna - avatar
+ 1
https://code.sololearn.com/ca1cf1dYZ8PW/?ref=app I wrote this code a few days ago to find out the second largest no.
27th Mar 2019, 9:34 AM
Prakhar
+ 1
Prakhar Your code prints 3 for 3, 69, 285... You're not comparing numbers (1 < 2 < 15), but strings which are compared lexicographically ('1' < '15' < '2')...
27th Mar 2019, 10:02 AM
Anna
Anna - avatar