Welcome back for a little way of
the programmer advice on naming the variables in your for-loops.
So, suppose that x was a variable whose bound to a list somewhere,
you might be tempted to write for y and x print(y).
The problem is, if you haven't looked at this code in awhile,
and x was defined somewhere above this code, what is x?
You haven't given it a name that gives any suggestion
that it's even a list much less what it's a list have.
I have for y and x also I'm not,
with my code here I'm not giving any hint
as to what kinds of items are supposed to be in x.
So, this is a very simple for-loop,
you might be able to get away with this and still be able to understand what's going on,
but it's really going to be helpful if you give more meaningful names.
One bit of advice I have is to,
whenever you're having a variable name that's going to refer to a list,
give it a plural noun as its name,
and whenever you're going to have an iterator variable, give it a singular noun.
So, here's an example in my next code window.
I have a variable called genres.
Because it has a plural name with an S on the end,
I expect it to be probably a sequence.
Then I took my iterator variable and I chose to make it be a singular noun.
Moreover, it is a singular noun that goes with the plural noun So,
each item in a list called genres is going to be one genre.
And so, then in my code inside the for-loop,
I'm going to refer to this singular variables genre
and it's going to remind me that it's one item from the genres list.
This is a lot better than doing things like,
and I sometimes do see students confuse themselves.
They'll say, "for apples in fruit", and fruit actually,
you look at their code and it's a list of the names of fruits and
apples is the first string that's in that list,
and so somehow they decided that they would name the variable name apples,
but this'll be very confusing to read because you get four lines into
the code and you see apples somewhere, and you think, "Oh.
Apples must be a list of different kinds of apples or something like that. "
So, don't do this.
For fruit in fruits, that's fine.
So, for your sequence,
do a plural noun.
For your iterator variable,
do a singular noun.
Follow that little convention and you'll save yourself a lot of
confusions as you're coding. See you next time.