for i in list python index code example
Example 1: python for with iterator index
for index, value in enumerate(iterator):
print(index, value)
Example 2: python how to get index in for loop
index = 0
foods = ["burger", "pizza", "apple", "donut", "coconut"]
for food in foods:
print("Food", index, "is", food)
index += 1
foods = ["burger", "pizza", "apple", "donut", "coconut"]
for index, value in enumerate(foods):
print("Food", index, "is", value)
Example 3: find an index of an item in a list python
list = ['apples', 'bannas', 'grapes']
Index_Number_For_Bannas = list.index('apples')
print(list[Index_Number_For_Bannas])
Example 4: python iterate with index
for index, item in enumerate(iterable, start=1):
print index, item
Example 5: how to index lists in python
list = ['bananas', 'apples', 'watermellon']
print(list[1])