1 00:00:00,500 --> 00:00:02,700 Welcome back for a little way of 2 00:00:02,700 --> 00:00:06,380 the programmer advice on naming the variables in your for-loops. 3 00:00:06,380 --> 00:00:11,685 So, suppose that x was a variable whose bound to a list somewhere, 4 00:00:11,685 --> 00:00:15,720 you might be tempted to write for y and x print(y). 5 00:00:15,720 --> 00:00:20,160 The problem is, if you haven't looked at this code in awhile, 6 00:00:20,160 --> 00:00:26,130 and x was defined somewhere above this code, what is x? 7 00:00:26,130 --> 00:00:29,100 You haven't given it a name that gives any suggestion 8 00:00:29,100 --> 00:00:32,710 that it's even a list much less what it's a list have. 9 00:00:32,960 --> 00:00:37,260 I have for y and x also I'm not, 10 00:00:37,260 --> 00:00:39,780 with my code here I'm not giving any hint 11 00:00:39,780 --> 00:00:43,280 as to what kinds of items are supposed to be in x. 12 00:00:43,280 --> 00:00:46,250 So, this is a very simple for-loop, 13 00:00:46,250 --> 00:00:50,120 you might be able to get away with this and still be able to understand what's going on, 14 00:00:50,120 --> 00:00:55,770 but it's really going to be helpful if you give more meaningful names. 15 00:00:55,770 --> 00:00:59,375 One bit of advice I have is to, 16 00:00:59,375 --> 00:01:04,980 whenever you're having a variable name that's going to refer to a list, 17 00:01:05,050 --> 00:01:09,290 give it a plural noun as its name, 18 00:01:09,290 --> 00:01:14,660 and whenever you're going to have an iterator variable, give it a singular noun. 19 00:01:14,660 --> 00:01:19,340 So, here's an example in my next code window. 20 00:01:19,340 --> 00:01:23,860 I have a variable called genres. 21 00:01:23,900 --> 00:01:27,990 Because it has a plural name with an S on the end, 22 00:01:27,990 --> 00:01:33,250 I expect it to be probably a sequence. 23 00:01:35,120 --> 00:01:43,610 Then I took my iterator variable and I chose to make it be a singular noun. 24 00:01:44,160 --> 00:01:50,465 Moreover, it is a singular noun that goes with the plural noun So, 25 00:01:50,465 --> 00:01:54,925 each item in a list called genres is going to be one genre. 26 00:01:54,925 --> 00:01:58,330 And so, then in my code inside the for-loop, 27 00:01:58,330 --> 00:02:01,630 I'm going to refer to this singular variables genre 28 00:02:01,630 --> 00:02:07,000 and it's going to remind me that it's one item from the genres list. 29 00:02:07,100 --> 00:02:10,800 This is a lot better than doing things like, 30 00:02:10,800 --> 00:02:15,505 and I sometimes do see students confuse themselves. 31 00:02:15,505 --> 00:02:25,300 They'll say, "for apples in fruit", and fruit actually, 32 00:02:25,300 --> 00:02:28,720 you look at their code and it's a list of the names of fruits and 33 00:02:28,720 --> 00:02:33,490 apples is the first string that's in that list, 34 00:02:33,490 --> 00:02:37,180 and so somehow they decided that they would name the variable name apples, 35 00:02:37,180 --> 00:02:41,410 but this'll be very confusing to read because you get four lines into 36 00:02:41,410 --> 00:02:45,410 the code and you see apples somewhere, and you think, "Oh. 37 00:02:45,410 --> 00:02:50,515 Apples must be a list of different kinds of apples or something like that. " 38 00:02:50,515 --> 00:02:53,050 So, don't do this. 39 00:02:53,050 --> 00:03:02,050 For fruit in fruits, that's fine. 40 00:03:02,050 --> 00:03:07,360 So, for your sequence, 41 00:03:07,360 --> 00:03:10,010 do a plural noun. 42 00:03:10,850 --> 00:03:13,770 For your iterator variable, 43 00:03:13,770 --> 00:03:16,420 do a singular noun. 44 00:03:19,720 --> 00:03:23,810 Follow that little convention and you'll save yourself a lot of 45 00:03:23,810 --> 00:03:28,890 confusions as you're coding. See you next time.