Newbie: finding the key/index of the min/max element

Benjamin Han bhan at andrew.cmu.edu
Tue Apr 30 16:20:00 EDT 2002


In my quest of becoming a "Pythonistas" (where does this word come from BTW?), 
here comes my 2nd trivial question: how do you find the key/index of the 
max/min element in a sequence/map? I know you can call max(l) but this only 
gives you the element itself, not the key. I also know it's not that hard to 
code it up the hard way (for k in d.keys(): ... # do comparison), but is 
there a more elegant way of doing this?

Thanks,

Ben



More information about the Python-list mailing list