The pythonic way is to use enumerate
:
for idx, item in enumerate(my_list):
More Related Contents:
- How can I convert this python for-loop using a range into C++?
- How to print out the letters of a word, one on each line, with three asterisks before and after the word
- Finding the number of times characters from text1 occur in text2
- How to iterate through two lists in parallel?
- Python for-in loop preceded by a variable
- Scope of python variable in for loop
- How to check if all elements of a list match a condition?
- How can I iterate through two lists in parallel?
- Avoiding nested for loops
- Function with varying number of For Loops (python)
- Python: How to keep repeating a program until a specific input is obtained? [duplicate]
- How do I iterate through two lists in parallel?
- How do I loop through a list by twos? [duplicate]
- Why do I get an IndexError (or TypeError) from “ar[i]” inside “for i in ar”?
- Printing a list separated with commas, without a trailing comma
- For loop with custom steps in python
- Python lambda doesn’t remember argument in for loop [duplicate]
- Converting for loops to while loops in python
- Converting a number to binary with a fixed length
- Python nested looping Idiom
- Understanding for loops in Python
- How to increment variable names/Is this a bad idea [duplicate]
- Script skips second for loop when reading a file
- How do I annotate types in a for-loop?
- Is there a need for range(len(a))?
- for loops and iterating through lists – how does “for a[-1] in a:” work?
- Reverse a string without using reversed() or [::-1]?
- Modifying a list while iterating when programming with python [duplicate]
- Converting List Comprehensions to For Loops in Python
- Using a loop in Python to name variables [duplicate]