Index of maximum element in list
Paul Rubin
http
Sat Jan 26 05:25:22 EST 2008
bearophileHUGS at lycos.com writes:
> def posmax(seq, key=None):
> """Return the position of the first maximum item of a sequence.
> It accepts the usual key parameter too."""
> if key:
> return max(enumerate(seq), key=lambda k: key(k[1]))[0]
> else:
> return max(enumerate(seq), key=itemgetter(1))[0]
def posmax(seq, key=lambda x:x):
return max(enumerate(seq), key=lambda k: key(k[1]))[0]
More information about the Python-list
mailing list