> For the complete documentation index, see [llms.txt](https://calnotes.gitbook.io/cs61a-guidebook/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://calnotes.gitbook.io/cs61a-guidebook/structures-of-data/iterables/deep-lists.md).

# 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](/files/PnkbAjX8N85s9zrFQdLI)

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!


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://calnotes.gitbook.io/cs61a-guidebook/structures-of-data/iterables/deep-lists.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
