Welcome to the Treehouse Community
Looking to learn something new?
Alexander Mazur3,543 Points
for item in new_list: shopping_list.insert(spot, item.strip())
I am a bit confused about the for loop. Where is item defined? And how does it determine how the for loop will run?
Okay, so in a for loop you will have:
for i in list:
The 'for' bit tells the program that this is a for loop. The 'i' bit is just a temporary variable (this means that it can be whatever you like. So you could have 'for item in list' for e.g. The 'in' part states that the data the loop needs to iterate over is coming next. The 'list' part is the name for the variable or list or whatever you want to iterate over. So if you wanted to iterate over a list called 'shopping_list', your for loop would read:
for item in shopping_list: #where I wrote 'item' you can write anything you like!
After that's set up you write what you actually want to to with each item. This may be print or find a certain index e.t.c.
So to conclude your final for loop syntax is:
for i in list: #Do stuff (i.e. print)
item doesn't need to be defined. it is just a variable we are using to describe what is in our list. the syntax works just fine as it is. it is a way of telling the program that for whatever thing that is the list do something. if it were a list of numbers you could say for number in new_list, or even for num in new_list, this will work just the same and give the same answer.