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. The best use of ChainMap is to search through multiple dictionaries at a time and get the proper key-value pair mapping.
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-map-function
Python map() function - GeeksforGeeks
We can use map() with multiple iterables if the function we are applying takes more than one argument. Example: In this example, map() takes two iterables (a and b) and applies lambda function to add corresponding elements from both lists.
Published   September 7, 2025
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.

🌐
Allendowney
allendowney.github.io › DSIRP › hashmap.html
Implementing Mapping Types — Data Structures and Information Retrieval in Python
find_map uses the built-in function hash, which takes almost any Python object and returns an integer. A limitation of this implementation is that it only works with hashable keys.
🌐
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 Python, mapping is often achieved using dictionaries, which are collections of key-value pairs. These key-value pairs enable efficient storage and retrieval of data, making maps an essential concept in various programming tasks, from data manipulation to algorithm implementation. ... In programming, a map, also known as a dictionary, hash map, or associative array, is a data structure ...
🌐
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.
🌐
Real Python
realpython.com › python-mappings
Python Mappings: A Comprehensive Guide – Real Python
July 23, 2024 - As shown in this example, you can’t use a list as a key in a dictionary since lists are mutable and not hashable. And even though number_groups is a tuple, you can’t use it to create a Counter object since the tuple contains lists. Mappings are not an ordered data structure. However, items in dictionaries maintain the order in which they were added. This feature has been present since Python ...
🌐
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).
Find elsewhere
🌐
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 - The origins of the word "mapping" are not as helpful as the etymologies of "iterable" and "sequence". A map, for example, shows us where countries are in the world by mapping their names to a geographical location. A Python mapping performs ...
🌐
Real Python
realpython.com › python-data-structures
Common Python Data Structures (Guide) – Real Python
October 21, 2023 - MappingProxyType is a wrapper around a standard dictionary that provides a read-only view into the wrapped dictionary’s data. This class was added in Python 3.3 and can be used to create immutable proxy versions of dictionaries. MappingProxyType can be helpful if, for example, you’d like to return a dictionary carrying internal state from a class or module while discouraging write access to this object.
🌐
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 many more problems that can be solved using the graph data structure. Also, there are many types of graphs like Null Graph, Infinite Graph, but we can not cover everything about graphs in this article so here is the link to learn more about it. ... Now in this code, we have created a class called Graph which takes edges as parameters as a list of tuples. Here the routes variable is an example of edges variable which has a list of tuples in which the first value of the tuple represents the start of the edge and the second value represents the end of that particular edge ( (“Mumbai”, “Paris”) Mumbai is the start of that edge and Paris is the end of that edge; and all the cities are represented as nodes).
🌐
Codecademy
codecademy.com › learn › learn-data-structures-and-algorithms-with-python › modules › hash-maps › cheatsheet
Learn Data Structures and Algorithms with Python: Hash Maps Cheatsheet | Codecademy
#This is a valid Hash Map where 2 keys share the same value ... Learn what data structures and algorithms are, why they are useful, and how you can use them effectively in Python.
🌐
Simplilearn
simplilearn.com › home › resources › software development › map function in python: simplify iterative operations
Map Function in Python: Simplify Iterative Operations
April 16, 2021 - 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
🌐
Chalmersgu-data-structure-courses
chalmersgu-data-structure-courses.github.io › OpenDSA › Published › ChalmersGU-DSABook › html › ListMap.html
4.7. Implementing Maps using Lists — Data Structures and Algorithms
class LinkedMap(Map): def __init__(self): self._head = None # Pointer to list header self._listSize = 0 # Size of list def put(self, key, value): current = self._head while current is not None: if key == current.key: oldValue = current.value current.value = value return oldValue current = current.next self._head = KVNode(key, value, self._head) self._listSize += 1 return None def get(self, key): current = self._head while current is not None: if key == current.key: return current.value current = current.next return None def remove(self, key): prev = None removed = self._head while removed is n
🌐
Medium
medium.com › codex › mastering-pythons-map-function-transform-data-like-a-pro-b3ea5114bca0
🔄 Mastering Python’s map() Function – Transform Data Like a Pro! | by Elshad Karimov | CodeX | Medium
November 14, 2024 - Let’s start with a simple example: converting a list of temperatures in Celsius to Fahrenheit. # Celsius temperatures celsius = [0, 20, 37, 100] # Lambda function to convert to Fahrenheit fahrenheit = list(map(lambda x: (x * 9/5) + 32, celsius)) ...
🌐
DataCamp
datacamp.com › tutorial › guide-to-python-hashmaps
A Guide to Python Hashmaps | DataCamp
December 3, 2024 - Hashmaps are incredibly versatile and efficient data structures. However, they also come with problems and limitations. To address the common challenges associated with hashmaps, it’s important to keep in mind some considerations and good practices. This makes sense: if the content of the key changes, the hash function will return a different hash, so Python won’t be able to find the value associated with the key. Hashing only works if each item maps ...
🌐
Edureka
edureka.co › blog › hash-tables-and-hashmaps-in-python
Hash Tables and Hashmaps in Python | Hash Table vs Hashmap | Edureka
November 27, 2024 - The elements of a dictionary are not ordered and they can be changed. An example of a dictionary can be a mapping of employee names and their employee IDs or the names of students along with their student IDs.
🌐
EyeHunts
tutorial.eyehunts.com › home › python map function | data structure| multiple arguments | examples
Python map Function | Data Structure | Multiple argu | Example - EyeHunts
May 18, 2021 - # get the length function def myfunc(n): return len(n) result = map(myfunc, ('EyeHunts', 'Python', 'Tutorial')) # get the list print(list(result)) ... As the upper code example and output, there is a duplicate value.
🌐
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: