Help us understand the problem. What is going on with this article?

pythonのenumerate関数

More than 5 years have passed since last update.

pythonでenumerate関数を使うと、拡張forループを回す時に、indexを一緒に返してくれる。

>>> for i, s in enumerate(['a', 'b', 'c']):
...     print i, s 
... 
0 a
1 b
2 c
>>> 
>>> for i, s in enumerate([('a', 'b'), ('c', 'd'), ('e', 'f')]):
...     print i, s
... 
0 ('a', 'b')
1 ('c', 'd')
2 ('e', 'f')

今のところ使う予定ないけど、面白そうだったので。

wwacky
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away