mapping

In Python, a mapping is a data structure that associates keys with values. The most common example of a mapping in Python is the built-in dict data type, which allows you to store and retrieve data by using unique keys.

Mappings are a powerful tool when you need to efficiently look up data based on a unique identifier. In Python, the dictionary is implemented as a hash table, which provides efficient lookups, insertions, and deletions in constant time, O(1).

Example

Here’s an example of how to create and use a dictionary:

Python
>>> ages = {
...     "Alice": 28,
...     "Bob": 34,
...     "Charlie": 22
... }

>>> ages["Alice"]
28
>>> ages["David"] = 30
>>> ages
{
    "Alice": 28,
    "Bob": 34,
    "Charlie": 22,
    "David": 30
}
>>> ages["Alice"] = 29
>>> ages
{
    "Alice": 29,
    "Bob": 34,
    "Charlie": 22,
    "David": 30
}

In this example, you use a Python dictionary to store and manipulate key-value pairs. You can access values by their keys, add new pairs, or update existing values. Dictionaries are pretty efficient for such operations.

Tutorial

Dictionaries in Python

In this tutorial, you'll learn how to work with Python dictionaries to help you process data more efficiently. You'll learn how to create dictionaries, access their keys and values, update dictionaries, and more.

basics python

For additional information on related topics, take a look at the following resources:


By Leodanis Pozo Ramos • Updated April 23, 2025
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy