listのindexを取得する
enumerateを使用する
PHPでいうとforeach
>>> list = ["apple", "orange", "banana"] >>> for index, value in enumerate(list): ... print index ... print value 0 apple 1 orange 2 banana
enumerateを使用する
PHPでいうとforeach
>>> list = ["apple", "orange", "banana"] >>> for index, value in enumerate(list): ... print index ... print value 0 apple 1 orange 2 banana