LoginSignup
8
8

More than 5 years have passed since last update.

Google+で見かけたコメントに,「Pythonでリストの何番目の要素が最大/最小か求める簡単な方法は?」というのがあった.真っ先に思いついたのが1行目のコードなのだけれど,2行目の方がより良いかな?

Last updated at Posted at 2012-03-16
max(xrange(len(x)), key=lambda i: x[i])
max(enumerate(x), key=lambda x: x[1])[0]
8
8
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
8