# Dictionary

> A collection of key and value pairs. You look a value up by its key.

**Field:** Software Development  
**Category:** Programming Concepts  
**Also known as:** Map, Hash Map, Associative Array, dict

## Think of it like

Think of it like a coat check. You hand over a ticket, and you get back your own coat.

## Definition

A dictionary is a collection that stores pairs: a key and a value. You look a value up by its key, not by a number. Each key appears only once, like each word in a real dictionary. Python calls it a dict, JavaScript uses an object or a Map, and many others call it a map. It is the fastest way to find one thing by its name.

## Example

A class app keeps ages as {"Emma": 36, "Jack": 12}. Asking for "Jack" gives back 12 at once.

## Example code

```python
>>> ages = {"Emma": 36, "Jack": 12}
>>> ages["Jack"]
12
>>> ages["Bo"]
KeyError: 'Bo'
```

Look up by name. A name that is not there gives an error.

## Why it matters

Settings, user records and counts are all looked up by name. A dictionary finds them without searching the whole list.

## Common mistake

Asking for a key that is not there and not checking first. Most languages give an error or a null.

## Three principles

- **Key and value.** Every entry is a pair.
- **Keys are unique.** Each key can appear only once.
- **Fast lookup.** Find by name, not by position.

## Related terms

- [Array](https://learn.benibix.com/term/development/array)
- [Set](https://learn.benibix.com/term/development/set)
- [String](https://learn.benibix.com/term/development/string)
- [Null](https://learn.benibix.com/term/development/null)

## Told apart from

- [Dictionary vs Set](https://learn.benibix.com/compare/dictionary-vs-set): People think a set is just a dictionary with no values, because in Python both are written with curly brackets. A dictionary pairs each key with a value, so you look a value up by its key. A set holds single values, each one once, and has nothing to look up. In Python, {} on its own makes an empty dictionary. An empty set is written set().

## Taught in

- [Lists, Dictionaries and Sets](https://learn.benibix.com/learn/development-concepts/lists-dictionaries-and-sets): Programming Basics, 8/18

---

Source: https://learn.benibix.com/term/development/dictionary
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-19
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
