1 00:00:08,000 --> 00:00:14,160 Welcome back. One more thing to note about dictionaries is aliasing. 2 00:00:14,160 --> 00:00:16,125 So, on line one, 3 00:00:16,125 --> 00:00:20,520 we create a dictionary that has three key value pairs. 4 00:00:20,520 --> 00:00:27,435 On line two, we assign a new variable called alias to be that dictionary. 5 00:00:27,435 --> 00:00:31,140 On line four, we print out is alias opposites. 6 00:00:31,140 --> 00:00:34,695 This is asking, are they pointing to the same object? 7 00:00:34,695 --> 00:00:39,580 So, if we run CodeLens on lines one through four, 8 00:00:39,950 --> 00:00:44,510 then we'll see again line one creates a dictionary and 9 00:00:44,510 --> 00:00:50,090 line two assigned alias to point to the exact same object of that dictionary. 10 00:00:50,090 --> 00:00:53,215 Now, this is important because here, 11 00:00:53,215 --> 00:00:56,925 if we say alias sub right equals left, 12 00:00:56,925 --> 00:01:01,245 we're assigning right from its previous value which was wrong, 13 00:01:01,245 --> 00:01:04,890 and then we print out opposites sub right, 14 00:01:04,890 --> 00:01:09,950 then we're actually going to print out left on line seven. 15 00:01:09,950 --> 00:01:17,554 So, here, we can see line four says true because alias is the same object as opposites. 16 00:01:17,554 --> 00:01:20,380 But now, when we print out opposites sub right, 17 00:01:20,380 --> 00:01:21,885 we now get left. 18 00:01:21,885 --> 00:01:27,035 That's despite the fact that we first assigned opposite sub right to be wrong, 19 00:01:27,035 --> 00:01:29,480 and in all of these lines, 20 00:01:29,480 --> 00:01:33,035 we never directly changed opposites sub right. 21 00:01:33,035 --> 00:01:35,765 But the culprit here is that on line six, 22 00:01:35,765 --> 00:01:38,375 when we changed alias sub right to be left, 23 00:01:38,375 --> 00:01:41,090 then that also have changed opposite sub right. 24 00:01:41,090 --> 00:01:44,585 Again, we can use CodeLens to see why that is. 25 00:01:44,585 --> 00:01:46,540 So, on line one, 26 00:01:46,540 --> 00:01:53,090 we create a dictionary and then we assign alias to be that exact same dictionary. 27 00:01:53,090 --> 00:01:56,075 We can see alias is opposites. 28 00:01:56,075 --> 00:01:59,890 Now, when we assign alias sub right to now be left, 29 00:01:59,890 --> 00:02:02,160 then that modifies that dictionary. 30 00:02:02,160 --> 00:02:05,855 So, if that right is now left and that change 31 00:02:05,855 --> 00:02:10,940 the value associated with the key right to be left for both opposites and alias. 32 00:02:10,940 --> 00:02:14,630 So, let's go through a question related to this. 33 00:02:14,630 --> 00:02:17,185 So, here, on the first line, 34 00:02:17,185 --> 00:02:18,590 we create a dictionary with 35 00:02:18,590 --> 00:02:25,249 four key value pairs and then we assign yourdict to be my dictionary. 36 00:02:25,249 --> 00:02:29,260 So, yourdict is pointing to the same dictionary. 37 00:02:29,260 --> 00:02:34,620 Then, we say yourdict sub elephant equals 999. 38 00:02:34,620 --> 00:02:39,345 Now, remember, yourdict and mydict are the same object here. 39 00:02:39,345 --> 00:02:43,290 So, when we assign it elephant to be 999, 40 00:02:43,290 --> 00:02:47,690 that erases the value 23 and replaces it with 41 00:02:47,690 --> 00:02:53,680 999 for both of these dictionaries because they're pointing at the same object. 42 00:02:53,680 --> 00:02:57,315 So, now, when we print out mydictionary sub elephant, 43 00:02:57,315 --> 00:03:01,390 then we're going to get the value 999. 44 00:03:02,360 --> 00:03:06,160 That's all for now, until next time.