Index of maximum element in list

bearophileHUGS at lycos.com bearophileHUGS at lycos.com
Sat Jan 26 11:28:12 EST 2008


Paul Rubin:
> def posmax(seq, key=lambda x:x):
>    return max(enumerate(seq), key=lambda k: key(k[1]))[0]

Is the Python max able to tell that's the identity function? I don't
think so, so your version may be slower and more memory hungry in the
common situation where you don't have a key function. So I think my
version is better :-)

Bye,
bearophile



More information about the Python-list mailing list