Use a Dict :

m = {"A1" : [], "B3" : []}
m["A1"].append(1)
m["A1"].append(2)
m["B3"].append(3)

Note that you need to insert the key first in the dictionary, otherwise it would show KeyError. If you want to add a new key, suppose "A2" here, simply do :

m["A2"] = []

To sort the dictionary according to its keys, use an OrderedDict :

m = OrderedDict(sorted(m.items(), key = lambda t : t[0]))

One more thing, only non-mutable items such as strings, tuples, int, etc. are allowed as keys in a python dictionary, you can't have a dictionary with a list like [1,2,3] as one of the keys.

Answer from Jarvis on Stack Overflow
🌐
TutorialsPoint
tutorialspoint.com › home › python_data_structure › python maps
Understanding Python Maps
February 21, 2009 - Python Maps also called ChainMap is a type of data structure to manage multiple dictionaries together as one unit. The combined dictionary contains the key and value pairs in a specific sequence eliminating any duplicate keys.
🌐
Python documentation
docs.python.org › 3 › tutorial › datastructures.html
5. Data Structures — Python 3.14.3 documentation
Another useful data type built into Python is the dictionary (see Mapping Types — dict).
Discussions

c++ - python data structure: map - Stack Overflow
A minor note: Dicts in Python aren't ordered; they happen to be ordered in very new versions of CPython 3, but that's an implementation detail. Therefore, OrderedDict is the most applicable datastructure here, to ensure that your code is portable. More on stackoverflow.com
🌐 stackoverflow.com
A data-structure for 1:1 mappings in python? - Stack Overflow
I have a problem which requires a reversable 1:1 mapping of keys to values. That means sometimes I want to find the value given a key, but at other times I want to find the key given the value. B... More on stackoverflow.com
🌐 stackoverflow.com
are dictionary/maps the core data structure of any programming language?
They're not really a "core data structure of any programming language", but they're definitely a core data structure of Python. Internally, they're represented as hash tables with some extra optimizations. More on reddit.com
🌐 r/Python
9
0
April 8, 2022
Lack of TreeMap equivalent in Python
The only use case that I support adding sortedMap into the standard library is for interview. Because when interview, we cannot install packages in some platforms like coderpad, for many hard algorithm problems, we cannot resolve it without sortedMap or treeMap... More on reddit.com
🌐 r/Python
64
0
June 29, 2024
🌐
Medium
medium.com › pythoneers › understanding-how-maps-work-in-python-ce7102539bad
Understanding How Maps Work in Python | by Rajat Sharma | The Pythoneers | Medium
April 13, 2024 - ... In programming, a map, also known as a dictionary, hash map, or associative array, is a data structure that stores items in a collection where each item is associated with a key.
Top answer
1 of 2
2

Use a Dict :

m = {"A1" : [], "B3" : []}
m["A1"].append(1)
m["A1"].append(2)
m["B3"].append(3)

Note that you need to insert the key first in the dictionary, otherwise it would show KeyError. If you want to add a new key, suppose "A2" here, simply do :

m["A2"] = []

To sort the dictionary according to its keys, use an OrderedDict :

m = OrderedDict(sorted(m.items(), key = lambda t : t[0]))

One more thing, only non-mutable items such as strings, tuples, int, etc. are allowed as keys in a python dictionary, you can't have a dictionary with a list like [1,2,3] as one of the keys.

2 of 2
1

In Python, the equivalent of a hashmap is a Dict (in fact, most implementation of Dict are hashmaps). To ensure ordering across implementations, you will want to use an OrderedDict. A List is equivalent to a vector. Therefore, what you want is an OrderedDict of Lists.

from collections import OrderedDict

// Create the dictionary
d = {'A1': [1, 2], 'B2': [2, 3]}

// Order it by key
m = OrderedDict(sorted(d.items(), key=lambda t: t[0]))

// Example of appending to one of the lists
m['A1'].append(3)

print(m)

This will print:

OrderedDict([('A1', [1, 2, 3]), ('B2', [2, 3])])

You can also add additional keys containing Lists like this:

m["B2"] = [2, 3, 5, 7]

You will then need to re-sort the OrderedDict.

A minor note: Dicts in Python aren't ordered; they happen to be ordered in very new versions of CPython 3, but that's an implementation detail. Therefore, OrderedDict is the most applicable datastructure here, to ensure that your code is portable. I'm mentioning this because many people are very excited about this feature of CPython, but it's not guaranteed to work everywhere.

🌐
GeeksforGeeks
geeksforgeeks.org › dsa › introduction-to-map-data-structure
Introduction to Map – Data Structure and Algorithm Tutorials - GeeksforGeeks
July 23, 2025 - While Python's built-in dict provides the core functionality for maps, several additional types offer specialized features: collections.defaultdict: This type allows you to specify a default value for missing keys. When you try to access a key that doesn't exist, the default value is returned instead of raising a KeyError . This is useful for avoiding errors when dealing with optional data...
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-map-function
Python map() function - GeeksforGeeks
map() function in Python applies a given function to each element of an iterable (list, tuple, set, etc.) and returns a map object (iterator). It is a higher-order function used for uniform element-wise transformations, enabling concise and ...
Published   September 7, 2025
🌐
The Python Coding Stack
thepythoncodingstack.com › p › mappings-in-python-data-structure-3
Finding Your Way To The Right Value • Python's Mappings (Data Structure Categories #3)
May 11, 2023 - And a Python mapping enables you to find your way from one object to another. As we saw in the previous article in this series, the order of the items in a sequence matters. In a mapping, the relationship between a pair of objects is what matters. We refer to the pair of objects as the key and the value. Let's see what makes a mapping and dig a bit beneath the surface to understand this category of data structures.
Find elsewhere
🌐
Allendowney
allendowney.github.io › DSIRP › hashmap.html
Implementing Mapping Types — Data Structures and Information Retrieval in Python
There is another data structure, called a hashtable that is even faster—it can do a search in constant time—and it doesn’t require the items to be sorted. Python dictionaries are implemented using hashtables, which is why most dictionary operations, including the in operator, are constant time. To explain how hashtables work and why their performance is so good, I start with a simple implementation of a map ...
🌐
Real Python
realpython.com › python-mappings
Python Mappings: A Comprehensive Guide – Real Python
July 23, 2024 - In this tutorial, you'll learn the basic characteristics and operations of Python mappings. You'll explore the abstract base classes Mapping and MutableMapping and create a custom mapping.
🌐
Plain English
python.plainenglish.io › an-introduction-to-python-data-structures-hash-map-tree-graph-9cf96078731a
An Introduction to Python Data Structures — Hash-map, Tree, Graph | by Nandit Shah | Python in Plain English
May 5, 2021 - There are various types of non-linear data structuresbut we will cover — ... Basically, Hash-map is a key-value pair type of data structure in which the key is calculated using the Hash function and then that data is stored as key (calculated ...
🌐
DataCamp
datacamp.com › tutorial › guide-to-python-hashmaps
A Guide to Python Hashmaps | DataCamp
December 3, 2024 - A hashmap is a data structure that stores key-value pairs by transforming keys into indexes using a hash function, enabling fast data retrieval and updates.
🌐
dbader.org
dbader.org › blog › python-dictionaries-maps-and-hashtables
Dictionaries, Maps, and Hash Tables in Python – dbader.org
April 18, 2017 - Need a dictionary, map, or hash table to implement an algorithm in your Python program? Read on to see how the Python standard library can help you. In Python, dictionaries (or “dicts”, for short) are a central data structure:
🌐
Codecademy
codecademy.com › article › python-data-structures
A Guide to Python Data Structures | Codecademy
Here is a tree map that visualizes the classification of data structures in Python:
🌐
Simplilearn
simplilearn.com › home › resources › software development › map function in python: simplify iterative operations
Map Function in Python: Simplify Iterative Operations
1 month ago - Learn how to use the map function in Python to simplify iterative operations. Discover its benefits, usage, and practical examples for efficient coding.
Address   5851 Legacy Circle, 6th Floor, Plano, TX 75024 United States
🌐
Real Python
realpython.com › python-data-structures
Common Python Data Structures (Guide) – Real Python
October 21, 2023 - In Python, dictionaries (or dicts ... each identified by a unique dictionary key. Dictionaries are also often called maps, hashmaps, lookup tables, or associative arrays....
🌐
Reddit
reddit.com › r/python › are dictionary/maps the core data structure of any programming language?
are dictionary/maps the core data structure of any programming language? : r/Python
April 8, 2022 - They're not really a "core data structure of any programming language", but they're definitely a core data structure of Python.
🌐
Quora
quora.com › Are-there-any-data-structures-in-Python-similar-to-Hash-Maps-Sets-Tables-Data-Structures-in-Java
Are there any data structures in Python similar to Hash (Maps, Sets, Tables) Data Structures in Java? - Quora
Answer (1 of 3): In python a ‘dict’ behaves similar to a HashMap, it works with the help of hash tables. And, it has ‘set’ that relates to HashSet in Java. A ‘set’ also uses hash tables very similar to the ‘dict’. You probably won’t need a HashTable as it is obsolete now, HashMap can do what you...
🌐
Python Like You Mean It
pythonlikeyoumeanit.com › Module2_EssentialsOfPython › DataStructures_II_Dictionaries.html
Data Structures (Part II): Dictionaries — Python Like You Mean It
Data Structures (Part II): Dictionaries · View page source · Python’s dictionary allows you to store key-value pairs, and then pass the dictionary a key to quickly retrieve its corresponding value. Specifically, you construct the dictionary by specifying one-way mappings from key-objects to value-objects.