---
description: Visualizing lists.
---

# Deep Lists

Previously, we mentioned that a list is a collection of elements. Now, we develop this concept with a question — can a list be an element? The answer is yes! Something like the following is extremely possible in Python:

```
lst = [1, [2, 3], [4, 5, 6]]
```

The above is a list where the first element is `1`, the second element is `[2, 3]` and the third element is `[4, 5, 6]`. Let's also take a moment to look at the visualization, as generated by [PythonTutor](https://pythontutor.com/visualize.html#mode=edit):

![List Visualized](https://4263597606-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FCNHWz8Kc9I8iz7vZD9dJ%2Fuploads%2FHs6OqImSGkeUCBcK5yTu%2FScreen%20Shot%202022-01-07%20at%206.18.21%20PM.png?alt=media\&token=059d765b-0730-4d9b-b9d0-aca36d6b3d45)

Wait, what are these arrows? These arrows are **pointers to the list that we created.** Here, we tackle one of the most challenging concepts of this class: **The variable `lst` is not the list itself but a pointer to that list.** Similarly, the first element of the list is not the list `[2, 3]` but rather a pointer to the list `[2, 3]`.&#x20;

Lists that contain other lists are known as "deep lists". Conversely, lists without any other iterables as elements are known as "shallow lists". You'll see these phrases popping up time and again in this book and in 61A — some functions on lists are "shallow", in that they only execute on the list passed in as the argument and not any lists within it. Similarly, some functions are "deep", in that they execute on the list passed in as the argument, and every list within it. The distinction is critical!&#x20;

While this concept might not feel very important right now, it is going to get particularly interesting as we further our understanding of lists. Keep this in the back of your mind as you tackle list questions!
