# Lists, Dictionaries and Sets

> How a program keeps many values under one name. Lists and their index numbers, key and value pairs, sets with no repeats, and tuples.

**Course:** [Programming Basics](https://learn.benibix.com/learn/development-concepts)  
**Time:** 13 min

**After this lesson you can:**

- Read an item from a list by its index
- Look a value up in a dictionary by its key
- Pick a list, dictionary, set or tuple for a job

## How to keep many values under one name

A collection keeps many values under one name. Python has four common ones: the list, the dictionary, the set and the tuple. A list of 3 names is written ["Ana", "Ben", "Cy"]. Each one is built for a different job, so picking the right one makes the rest of the code simpler.

A list is Python's version of an array: values kept in order, each in a numbered spot. That number is the index, and it starts at 0, not 1. So in names = ["Ana", "Ben", "Cy"], names[0] is Ana and names[2] is Cy. names[-1] counts from the end and also gives Cy.

Starting at 0 trips up almost everyone at first. A list of 3 items has spots 0, 1 and 2. There is no spot 3, so names[3] fails with an IndexError. len(names) gives 3, which is one more than the last index.

A dictionary stores pairs: a key and its value. prices = {"tea": 2.5, "cake": 3.0} pairs each item with a price. You look a value up by its key, as in prices["tea"], rather than by a number. Since Python 3.7, a dictionary keeps its pairs in the order you added them.

A set holds values with no repeats. Put 1, 2, 2 and 3 into a set, and it keeps 1, 2 and 3. It has no order and no index. Sets are fast at one question: is this value in here? That makes them good for things like a list of banned words.

A tuple is like a list that cannot change once it is made. It is written with round brackets, such as (3, 4) for a point on a grid. Use one for a small group of values that belong together and should stay fixed.

Two mix-ups are common. {} on its own makes an empty dictionary, not an empty set. Write set() for that. And a dictionary key must be unique: add "tea" twice and the second value simply replaces the first.

```python
names = ["Ana", "Ben", "Cy"]     # list
print(names[0], names[-1])       # Ana Cy

prices = {"tea": 2.5, "cake": 3.0}   # dictionary
print(prices["tea"])             # 2.5

tags = {"red", "blue", "red"}    # set, no repeats
print(len(tags))                 # 2

point = (3, 4)                   # tuple, fixed
```
Four collections. The list and tuple keep order, the dictionary pairs keys with values, and the set drops repeats.

![Four panels. A list shows Ana, Ben and Cy in boxes numbered 0, 1 and 2. A dictionary shows tea paired with 2.5 and cake paired with 3.0. A set shows red and blue in a loose circle, with a second red left out. A tuple shows 3 and 4 in locked slots.](https://learn.benibix.com/diagrams/prog-collections.svg)

### Example: Lucy builds a class register

Lucy keeps 28 pupils in a list, so she can print them in seating order. Their test marks go in a dictionary, keyed by name.

She wants the clubs the pupils joined, with each club named once. She puts all 41 sign-ups into a set and gets 6 clubs back.

**Words in this lesson:** [Array](https://learn.benibix.com/term/development/array), [Index](https://learn.benibix.com/term/development/index), [Dictionary](https://learn.benibix.com/term/development/dictionary), [Set](https://learn.benibix.com/term/development/set), [Tuple](https://learn.benibix.com/term/development/tuple)

**Question:** In names = ["Ana", "Ben", "Cy"], what is names[1]?

**Answer:** Ben. The index starts at 0. So names[0] is Ana, names[1] is Ben and names[2] is Cy.

---

Source: https://learn.benibix.com/learn/development-concepts/lists-dictionaries-and-sets
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.
