-6

Need to print second Maximum Number in a given List Description - Given a list of numbers, find the second largest number in the list.

Note:- There might be repeated numbers in the list. If there is only one number present in the list, return 'not present'.

I have tried to directly sort it but not able to make the not present condition

  • You can get some idea from here: https://stackoverflow.com/questions/39748916/find-maximum-value-and-index-in-a-python-list – mpx Mar 02 '21 at 05:39

1 Answers1

0

An easy implementation would be to do something like:

if len(set(input)) == 1:
   print('not present')
else:
   sorted(set(input))[-2]

Take a look at Get the second largest number in a list in linear time for other implementations.