1 00:00:07,910 --> 00:00:10,470 Welcome back everybody. 2 00:00:10,470 --> 00:00:13,800 You've already seen that you can use square brackets multiple 3 00:00:13,800 --> 00:00:18,375 times to extract an item from deep inside a nested data structure. 4 00:00:18,375 --> 00:00:21,840 Often, you'll want to traverse all the stuff that's in 5 00:00:21,840 --> 00:00:25,095 a nested data structure or at least some subset of it. 6 00:00:25,095 --> 00:00:30,855 Perhaps, you'll print all the items out or accumulate them into a flat, un-nested list. 7 00:00:30,855 --> 00:00:35,355 In this lesson, you'll do that through nested iteration, 8 00:00:35,355 --> 00:00:38,010 a for-loop indented inside a for-loop 9 00:00:38,010 --> 00:00:41,835 indented inside a for-loop as many levels as you need. 10 00:00:41,835 --> 00:00:45,590 We'll also look at the confusions that can occur from a list or 11 00:00:45,590 --> 00:00:50,195 dictionary being nested inside other lists or dictionaries. 12 00:00:50,195 --> 00:00:54,020 It's analogous to the problems of aliasing that we've seen before, 13 00:00:54,020 --> 00:00:57,310 where multiple variables point to the same object. 14 00:00:57,310 --> 00:01:00,300 If you mutate a list say by appending an extra item, 15 00:01:00,300 --> 00:01:04,940 you've effectively changed all the lists and dictionaries that contain that list. 16 00:01:04,940 --> 00:01:07,970 We'll introduce the notion of deep as opposed to 17 00:01:07,970 --> 00:01:11,260 shallow copies of nested data structures. 18 00:01:11,260 --> 00:01:15,090 Finally, we'll introduce the understand, extract, 19 00:01:15,090 --> 00:01:17,450 repeat method of incrementally figuring 20 00:01:17,450 --> 00:01:21,500 out how to extract data from a nested data structure. 21 00:01:21,500 --> 00:01:23,510 At the end of this lesson, 22 00:01:23,510 --> 00:01:26,540 you should be able to write nested for-loops, 23 00:01:26,540 --> 00:01:28,965 to traverse a nested data structure, 24 00:01:28,965 --> 00:01:34,380 recognize when an inner list or dictionary is shared among multiple outer objects, 25 00:01:34,380 --> 00:01:39,490 and if necessary make deep copies instead of shallow copies to avoid that, 26 00:01:39,490 --> 00:01:44,600 and you should be able to incrementally develop code to extract the data you want from 27 00:01:44,600 --> 00:01:49,925 a complex nested data structure using the understand, extract, repeat process. 28 00:01:49,925 --> 00:01:52,950 Bye for now. We'll see you at the end.