DEV Community

loading...

Discussion on: Day-19 Third Maximum Number

mridubhatnagar profile image
Mridu Bhatnagar Author

Cool! IMO still there is no need to create a new_list. Can you test the below code for some inputs? Should work.

def thirdMax(lister):
    lister = list(set(lister))
    if len(lister) > 3:
        for i in range(0,2):
            lister.remove(max(lister))
        result = max(lister)
    elif len(lister)==3:
        result = min(lister)
    else:
        result = max(lister)
    return result
Thread Thread
alex_twittelive profile image
Alex

Great !!! Thanks for your share...
I keep this. Best regards