LoginSignup
4
7

More than 5 years have passed since last update.

pythonのenumerate関数

Last updated at Posted at 2014-03-10

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')

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

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