Mappings

What is a mapping?

A mapping is a data structure that connects two more pieces of information, commonly called a key-value pair. When a key is asked, you get its associated value. One mapping structure can store multiple key-value pairs.

Why are mappings important?

Mappings don't just store data. They allow you to establish relationships between the data. For example, you could pair a password with each username, a capital with each country, and an author with each book.

What can you do with a mapping?

Mappings aren't limited to single pieces of data: you could use a single piece of data as a key and a sequence as the value. For example, you could pair a username with a sequnce of other users to define a relationship between one user and other users. This is the core of how many different social networks are implemented.

What is the main mapping type in Python?

In Python, the main mapping type is the dictionary. Make sure dictionaries are understandable to you, because many advanced Python data structures are represented by them.