looping over list python code example
Example 1: python loop through list
list = [1, 3, 6, 9, 12]
for i in list:
print(i)
Example 2: how to loop over list
list = [1, 2, 3, 4, 5, 6]
for item in list:
print(item)
for index in range(len(list)-1):
print(list[index])
for index, value in enumerate(list):
print(value)
Example 3: iterate through an array python
colors = ["red", "green", "blue", "purple"]
i = 0
while i < len(colors):
print(colors[i])
i += 1
Example 4: iterate over a list python
list = [1, 3, 5, 7, 9]
for i in list:
print(i)
Example 5: how to iterate over a list in python
lst = [10, 50, 75, 83, 98, 84, 32]
res = list(map(lambda x:x, lst))
print(res)