> For the complete documentation index, see [llms.txt](https://igb.mit.edu/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://igb.mit.edu/mini-courses/python/introduction-to-python-for-biologists/types/dictionaries.md).

# Dictionaries

<figure><img src="/files/gmMO9o7jkT95A90AyqYN" alt=""><figcaption><p>A dictionary is a fancy list</p></figcaption></figure>

* A dictionary consists of (key,value) pairs
* The key is an immutable type(e.g. a number, a string, a tuple)
* The value can be anything
* We retrieve the value in a dictionary by using the associated key
* Dictionaries are fancy lists that are not restricted to consecutive integers for indexing
* We create dictionaries with curly braces { }
* We assign elements to and retrieve elements from dictionaries with square brackets \[key]

```
In [1]: emails={}

In [2]: emails['Duan']='duan@mit.edu'

In [3]: emails['Charlie']='charliew@mit.edu'

In [4]: emails['Stuart']='slevine@mit.edu'

In [5]: emails['Allen']='asoberan@mit.edu'

In [6]: emails.keys()
Out[6]: ['Allen', 'Charlie', 'Duan', 'Stuart']

In [7]: emails.values()
Out[7]: ['asoberan@mit.edu', 'charliew@mit.edu', 'duan@mit.edu', 'slevine@mit.edu']

In [8]: emails
Out[8]: 
{'Charlie': 'charliew@mit.edu',
 'Duan': 'duan@mit.edu',
 'Allen': 'asoberan@mit.edu',
 'Stuart': 'slevine@mit.edu'}

In [9]: emails['Duan']
Out[9]: 'duan@mit.edu'

```

* Dictionaries can be constructed from a list of (key,value) pairs (or 2-turples)from two matching lists or keys and values

```
In [10]: instructors=['Duan','Charlie','Stuart','Allen']

In [11]: email=['duan@mit.edu','charliew@mit.edu','slevine@mit.edu','asoberan@mit.edu']

In [12]: adict=dict(zip(instructors,email))

In [13]: adict
Out[14]: 
{'Charlie': 'charliew@mit.edu',
 'Duan': 'duan@mit.edu',
 'Allen': 'asoberan@mit.edu',
 'Stuart': 'slevine@mit.edu'}
```


---

# 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, and the optional `goal` query parameter:

```
GET https://igb.mit.edu/mini-courses/python/introduction-to-python-for-biologists/types/dictionaries.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
