Loop through a list: for in : List Loop « List « Python






Loop through a list: for in

Loop through a list: for in
a = ['cat', 'window', 'defenestrate']

for x in a[:]: # make a slice copy of the entire list
    if len(x) > 6: a.insert(0, x)
 
print a


           
       








Related examples in the same category

1.List for iterationList for iteration
2.For StatementsFor Statements
3.To iterate over the indices of a sequence, combine range() and len()To iterate over the indices of a sequence, combine range() and len()
4.For loop demoFor loop demo
5.For loop for ListFor loop for List