1 00:00:07,960 --> 00:00:12,385 When in doubt, make a reference diagram. 2 00:00:12,385 --> 00:00:15,540 Even if you only might be in doubt, 3 00:00:15,540 --> 00:00:17,685 make a reference diagram. 4 00:00:17,685 --> 00:00:19,680 It's going to seem slow, 5 00:00:19,680 --> 00:00:22,875 painful, even to watch me do it. 6 00:00:22,875 --> 00:00:25,020 When you're doing it for the first few times it's going to 7 00:00:25,020 --> 00:00:27,354 be even slower and more painful, 8 00:00:27,354 --> 00:00:30,200 but it's worth it because it gives you a way of understanding 9 00:00:30,200 --> 00:00:33,730 things that can be pretty confusing otherwise. 10 00:00:33,730 --> 00:00:36,895 So, here's a little code example. 11 00:00:36,895 --> 00:00:39,985 Four lines and then we're printing out what's the result. 12 00:00:39,985 --> 00:00:45,760 But it's not so easy to figure out exactly what's going to print out. 13 00:00:45,760 --> 00:00:51,295 So, let's make a diagram to follow it. 14 00:00:51,295 --> 00:00:56,310 We're going to basically simulate like what CodeLens would do. 15 00:00:56,310 --> 00:00:58,220 We're going to do it ourselves. 16 00:00:58,220 --> 00:01:07,300 So, x on line one gets bound to a list of three items: one, two, three. 17 00:01:12,310 --> 00:01:19,080 On line two, y becomes an alias for x. 18 00:01:19,100 --> 00:01:23,700 On line three we have this x plus equals. 19 00:01:23,700 --> 00:01:26,860 Now, I gave you the suggestion that when you're dealing with lists, 20 00:01:26,860 --> 00:01:28,705 just don't use plus equals. 21 00:01:28,705 --> 00:01:30,070 But sometimes you have to read 22 00:01:30,070 --> 00:01:32,860 other people's code and they don't follow that good advice. 23 00:01:32,860 --> 00:01:36,660 So, suppose you had this x plus equals, 24 00:01:36,660 --> 00:01:43,690 that's the version where we're going to take the new list: four and five, 25 00:01:44,280 --> 00:01:49,535 and append them on to the old list, 26 00:01:49,535 --> 00:01:52,715 so that we now have a list of five items, 27 00:01:52,715 --> 00:01:57,945 and line three changes the object that x is pointing to. 28 00:01:57,945 --> 00:02:00,475 Since y is pointing to that same object, 29 00:02:00,475 --> 00:02:03,630 y now has five items as well. 30 00:02:03,680 --> 00:02:07,155 Next, on line four, 31 00:02:07,155 --> 00:02:13,190 we're going to use the better version that is a little easier to understand 32 00:02:13,190 --> 00:02:15,740 where we do the normal thing of 33 00:02:15,740 --> 00:02:18,800 figuring out the right hand side which takes the list: one, 34 00:02:18,800 --> 00:02:20,435 two, three, four, five, 35 00:02:20,435 --> 00:02:22,040 and appends another list to it, 36 00:02:22,040 --> 00:02:23,305 making a new list. 37 00:02:23,305 --> 00:02:25,410 So, then we have one, two, 38 00:02:25,410 --> 00:02:31,390 three, four, five, that's a list. 39 00:02:33,600 --> 00:02:41,455 We concatenate on this other list which contains six and then we reassign it. 40 00:02:41,455 --> 00:02:47,410 That's what this equal is doing so that y no longer points to what it used to point to, 41 00:02:47,410 --> 00:02:49,870 it now points to this new value. 42 00:02:49,870 --> 00:02:54,000 X, however, still points to the old value. 43 00:02:54,000 --> 00:02:57,885 So, when we print out x on line five, 44 00:02:57,885 --> 00:02:59,820 we're going to get five items, 45 00:02:59,820 --> 00:03:02,595 and we print out y on line six, 46 00:03:02,595 --> 00:03:05,075 we're going to get all six items. 47 00:03:05,075 --> 00:03:09,710 Let's check and see if that analysis is correct. 48 00:03:10,740 --> 00:03:15,420 Sure enough, line five prints out five items, 49 00:03:15,420 --> 00:03:18,375 line six prints out all six. 50 00:03:18,375 --> 00:03:20,790 Trying to do this in your head, 51 00:03:20,790 --> 00:03:22,640 especially if you ever end up with 52 00:03:22,640 --> 00:03:25,805 more than four lines of code that are doing things like this, 53 00:03:25,805 --> 00:03:27,380 very difficult to do. 54 00:03:27,380 --> 00:03:30,800 So remember, if there's anything even remotely confusing, 55 00:03:30,800 --> 00:03:32,285 make a reference diagram. 56 00:03:32,285 --> 00:03:35,900 Practice now even when it might not be so confusing. 57 00:03:35,900 --> 00:03:39,780 You'll thank me later. On to the next.