I tried list
new=[]
new=input()
print(new)
gives me a string as default. How to find the second largest integer from that? I have tried other answers that was found in this site but nothing worked for me.
I tried list
new=[]
new=input()
print(new)
gives me a string as default. How to find the second largest integer from that? I have tried other answers that was found in this site but nothing worked for me.
You can do it like this:
new = []
new = list(map(int, input().split(' ')))
new.sort()
print(new[-2])
It assumes that your input values are separeted by ' '. For example:
6 5 4 3 7 8
map() maps your strings into integers, which returns map-object. Then you can invoke a list() on it to get a list. After sorting you can get penultimate element by accessing [-2].