LoginSignup
4
2

More than 5 years have passed since last update.

[短文メモ][小ネタ]Pythonのenumerateで、インデックスを途中から始める

Posted at

実は第二引数startを指定すると、インデックスを途中から始められる。

for i, c in enumerate("abc", 1):
    print(i, c) # => "1 a", "2 b", "3 c"

こういうとき便利だけど、ちょっと冗長。

for i, x in enumerate(arr[offset:], offset):
    pass

参考: 公式ドキュメント

4
2
0

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
4
2