python enumerate

ループのときIndexがほしいときがある。

そんなときのenumerate。

list = ['a', 'b', 'c']
for i, e in enumerate(list):
  print(i) # 0,1,2
  print(e) # a,b,c

Built-in Functions – Python 3.9.5 documentation

The Python interpreter has a number of functions and types built into it that are always available. They are listed here in alphabetical order. Return if all elements of the iterable are true (or if the iterable is empty). Equivalent to: Return if any element of the iterable is true.