Locked lesson.
About this lesson
We'll look at multidimensional lists, or - lists of lists.
Exercise files
Download this lesson’s related exercise files.
Lists of Lists.docx58.9 KB Lists of Lists - Solution.docx
58.9 KB
Quick reference
Lists of Lists
A list can contain another list.
When to use
If you need to store a list, inside of another list; this is how you do it.
Instructions
Lists can contain all sorts of data...including other lists. There are two main ways to do it, directly and indirectly.
Directly:
my_list = ["John", "Tim", "Mary, [1,2,3,4]]
Indirectly:
second_list = [1,2,3,4]
my_list = ["John", "Tim", "Mary, second_list]
You can access items from the second array like this:
print(my_list[3][1])
Hints & tips
- Lists can contain other lists
- Enter them directly (just type them in) or indirectly (reference them by list name)
Lesson notes are only available for subscribers.