max(xrange(len(x)), key=lambda i: x[i])
max(enumerate(x), key=lambda x: x[1])[0]
More than 5 years have passed since last update.
Google+で見かけたコメントに,「Pythonでリストの何番目の要素が最大/最小か求める簡単な方法は?」というのがあった.真っ先に思いついたのが1行目のコードなのだけれど,2行目の方がより良いかな?
Last updated at Posted at 2012-03-16
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme
List of users who liked
88