Retrieving and Updating Elements
You retrieve and update elements in a multi-dimensional list the same way you would for 1D lists, except now you have to deal with multiple levels of indices. The table below shows how you would retrieve each value in my_list. Do you see any patterns?
You can also think about multi-dimensional lists this way:
The first index is the first "level" of the list. The second index is the second "level" of the list. It's list-ception!
Let's say we're trying to retrieve my_list. How would we get there?
First, look at the first level. We need to retrieve the element at index 1. That would be
['docs', 'slides', 'sheets']
['google', 'amazon', 'facebook']
['this', 'is', 'python']
Now we can go a level deeper. The next index is 2, so that would be:
Therefore, my_list is 'sheets'!
Copyright © 2021 Code 4 Tomorrow. All rights reserved. The code in this course is licensed under the MIT License. If you would like to use content from any of our courses, you must obtain our explicit written permission and provide credit. Please contact firstname.lastname@example.org for inquiries.