I have list like following
m=[['abc','x-name',222],['pqr','y-name',333],['mno','j-name',333],['qrt','z-name',111],['dcu','lz-name',999]]
Let's say I want to get top 2 out of this list considering 3rd column(i.e 222 or etc)
I know I can get the Max one like following
>>> m=[['abc','x-name',222],['pqr','y-name',333],['mno','j-name',333],['qrt','z-name',111],['dcu','lz-name',999]]
>>> print max(m, key=lambda x: x[2])
['dcu', 'lz-name', 999]
but what I have to get top 2 (considering the duplicates) my result should be
['dcu', 'lz-name', 999] ['pqr','y-name',333] ['mno','j-name',333]
Is it possible? I head is spinning trying to figure it out, can you pls have look and help me..
OR -just got idea
You can tell me to delete MAX element so that I can get top 2 elements using iteration( duplicate will be a problem though)