Exercise 39. Dictionaries, Oh Lovely Dictionaries

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:

Exercise 39 Python Session

>>> things = ['a', 'b', 'c', 'd']>>> print(things[1])b>>> things[1] = 'z'>>> print(things[1])z>>> things['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 know this about lists ...

Get Learn Python 3 the Hard Way: A Very Simple Introduction to the Terrifyingly Beautiful World of Computers and Code now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.