Want to find the second max number from the input | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
- 1

Want to find the second max number from the input

n = int(input()) a = input().split() a.sort() for i in range(0,n+1): if(a[-1-i]!=a[-1]): print(a[-1-i]) break; Here a.sort() cant sort the array if negetive numbers given

17th Dec 2021, 4:06 AM
Nisha
4 Answers
0
Nisha you are not doing it right. You can do it this way: a = list(map(int,input().split())) The function *map* takes two arguments , the first is a function and the second is a list, it then calls the function you passed as an argument with every value on the list you also passed as an argument. I think this is almost the same: a = [int(x) for x in input().split()] (this also work for what you want to do) Hope i explained the right way.
17th Dec 2021, 1:07 PM
Bakteria
Bakteria - avatar
+ 1
you are using the array **a** as an array of string, you need to convert each element to integer (you can use the **map** function) and then sort the array
17th Dec 2021, 4:16 AM
Bakteria
Bakteria - avatar
+ 1
Bakteria this line also doesn't work a = map[int(input()).split()]
17th Dec 2021, 11:11 AM
Nisha
0
take the input inside for loop, append it in empty list and then use sort()
17th Dec 2021, 6:14 AM
Ayush Kumar
Ayush Kumar - avatar