- 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
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.
+ 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
+ 1
Bakteria this line also doesn't work
a = map[int(input()).split()]
0
take the input inside for loop, append it in empty list and then use sort()