February 2024
Beginner
352 pages
8h 16m
English
You are now going to learn about the dictionary data structure in Python. A dictionary (or “dict”) is a way to store data just like a list, but instead of using only numbers to get the data, you can use almost anything. This lets you treat a dict like it’s a database for storing and organizing data.
Let’s compare what dicts can do to what lists can do. You see, a list lets you do this:
Listing 43.1: ex43_pycon_out.py
1 >>> things = ['a', 'b', 'c', 'd']
2 >>> print(things[1])
3 b
4 >>> things[1] = 'z'
5 >>> print(things[1])
6 z
7 >>> things
8 ['a', 'z', 'c', 'd']
You can use numbers to “index” into a list, meaning you can use numbers to find out what’s in lists. You should ...
Read now
Unlock full access