xxxxxxxxxx
mylist = [1, 2, 3, 4, 5] # "mylist = list(range(5))" does the same
for n in mylist:
print(n)
# output:
# >>> 1
# >>> 2
# >>> 3
# >>> 4
# >>> 5
xxxxxxxxxx
# Python code to iterate over a list
list = [1, 2, 3, 4, 5, 6]
# Method 1: Using "var_name in list" syntax
# Pro: Consise, easily readable
# Con: Can't access index of item
for item in list:
print(item)
# Method 2: Using list indices
# Pro: Can access index of item in list
# Con: Less consise, more complicated to read
for index in range(len(list)-1):
print(list[index])
# Method 3: Using enumerate()
# Pro: Can easily access index of item in list
# Con: May be too verbose for some coders
for index, value in enumerate(list):
print(value)
xxxxxxxxxx
list = [1, 3, 5, 7, 9]
# with index
for index, item in enumerate(list):
print (item, " at index ", index)
xxxxxxxxxx
# Python list
my_list = [1, 2, 3]
# Python automatically create an item for you in the for loop
for item in my_list:
print(item)
xxxxxxxxxx
# Python3 code to iterate over a list
list = [1, 3, 5, 7, 9]
# Using for loop
for i in list:
print(i)
xxxxxxxxxx
List<int> list = new List<int> { 1, 2, 3, 4, 5 };
//For Loop
for (int i = 0; i < list.Count(); i++)
{ Console.WriteLine(list[i]); }
//For Each Loop
foreach (int item in list)
{ Console.WriteLine(item); }
xxxxxxxxxx
for i in range(len(Latitudes)):
Lat,Long=(Latitudes[i],Longitudes[i])