To loop through a list and print the index of each item in the list, you can use the enumerate() function in Python. Here's an example:
main.py138 chars5 linesThis will output:
main.py117 chars5 lines
In the loop, enumerate(my_list) returns a sequence of tuples, where each tuple contains an index and a corresponding item from the list. The for loop unpacks each tuple into the index and item variables, which you can then use to print the desired output.
gistlibby LogSnag