Python dictionary is a built-in type that supports key-value pairs. It's the nearest builtin data structure relative to Java's HashMap.

You can declare a dict with key-value pairs set to values:

streetno = {
    "1": "Sachin Tendulkar",
    "2": "Dravid",
    "3": "Sehwag",
    "4": "Laxman",
    "5": "Kohli"
}

You can also set a key-value mapping after creation:

streetno = {}
streetno["1"] = "Sachin Tendulkar"
print(streetno["1"]) # => "Sachin Tendulkar"

Another way to create a dictionary is with the dict() builtin function, but this only works when your keys are valid identifiers:

streetno = dict(one="Sachin Tendulkar", two="Dravid")
print(streetno["one"]) # => "Sachin Tendulkar"
Answer from Alan on Stack Overflow
🌐
DataCamp
datacamp.com › tutorial › guide-to-python-hashmaps
A Guide to Python Hashmaps | DataCamp
December 3, 2024 - There are other hashing methods in sklearn, including FeatureHasher and DictVectorizer. Our School Budgeting with Machine Learning in Python case study is a great example where you can learn how they work in practice. Congratulations on finishing this tutorial on hashmaps.
🌐
GeeksforGeeks
geeksforgeeks.org › python › hash-map-in-python
Hash Map in Python - GeeksforGeeks
October 25, 2025 - Example: Let's create a hashmap and perform different operations to check if our class is working correctly.
🌐
Turing
turing.com › kb › how-to-use-hashmap-in-python
All You Need to Know About Using Hashmaps in Python
It's just an example to illustrate how a hash function might work in Python. For a more efficient hash function, you should use one of the built-in options provided by Python, such as the hash() function. my_key = "hashmap" my_hash_value = hash(my_key) print(my_hash_value) # Output: -7206927305943102685
🌐
StrataScratch
stratascratch.com › blog › easy-guide-to-python-hashmaps
Easy Guide to Python Hashmaps - StrataScratch
December 16, 2024 - In this section, I’ll cover two basic areas of Python hashmap knowledge. Python dictionaries rely on hashing—a process where a unique, fixed-size identifier (a hash) is generated for keys. Behind the scenes, Python uses an optimized hash table algorithm, ensuring constant-time complexity for most operations. Here’s an example of how hashing is done, where the input value is x, and the number of hash keys is n.
🌐
YoungWonks
youngwonks.com › blog › python-hashmap
Does Python have a HashMap? What is the equivalent of a HashMap in Python? Is dictionary in Python same as HashMap in Java?
November 26, 2023 - In this example, the values "value1", "value2", and "value3" are stored in a list and assigned to the key "key". Now, if you want to add a new value to this key, you will append the value to the list associated with the key: ... This dictionary allows you to quickly lookup the index of any item in the original list. The following are some of the applications of HashMaps in Python:
🌐
YouTube
youtube.com › codebagel
HashMaps in Python Tutorial - Data Structures for Coding Interviews - YouTube
Data structures are one of the most important things to prepare for coding interviews. HashMaps are one of the most essential data structures to know, and to...
Published   September 24, 2023
Views   116K
🌐
AskPython
askpython.com › home › implementing hashmaps in python
Implementing HashMaps in Python - AskPython
September 11, 2022 - After that we are taking the modulus ... output space for i in range(len(key)): hash_value = (hash_value + ord(key[i]) * i) % len(self.data) return hash_value def set(self, key, value): # Represents the index position where we want ...
Find elsewhere
🌐
CodeGym
codegym.cc › java blog › learning python › hashmap in python
HashMap in Python
November 13, 2024 - Python will automatically overwrite the existing value: # Updating Bob's phone number phone_book["Bob"] = "555-9999" Bob’s phone number has now been updated in phone_book. Once your data is stored in a HashMap, you can easily retrieve or remove it as needed.
🌐
Besant Technologies
besanttechnologies.com › home › blogs › general › hash tables and hashmaps in python
Hash Tables and Hashmaps in Python | Besant Technologies
October 7, 2021 - Hashmaps or Hash Tables in Python are implemented via the built-in data type. The keys of the built-in data type are generated with the help of a hashing function. The dictionary elements are not designed to be ordered and therefore they can be easily changed. Mapping of names of the student or employee with their Personal ID’s can be the best example ...
🌐
Roadmap
roadmap.sh › python › hashmap
Hashmaps in Python: Master Implementation and Use Cases
January 28, 2026 - Explain how hashmap in Python uses hashing to find values in a dictionary, and compare it with how lists perform lookups and then create a Python tutorial on it. Below is an example of a hashmap in Python using a dictionary:
🌐
W3Schools
w3schools.com › dsa › dsa_data_hashmaps.php
W3Schools.com
Well organized and easy to understand Web building tutorials with lots of examples of how to use HTML, CSS, JavaScript, SQL, PHP, Python, Bootstrap, Java and XML.
🌐
Analytics Vidhya
analyticsvidhya.com › home › a guide to python hashmaps
A Guide to Python HashMaps
June 7, 2024 - You can understand the inner workings of hash-based data structures by creating your own Hash Map in Python. A rudimentary implementation includes essential features like insertion, retrieval, deletion, and resizing. This approach uses open addressing for both dynamic scaling and collision resolution. class HashMap: def __init__(self, initial_capacity=8, load_factor=0.75): self.capacity = initial_capacity self.load_factor = load_factor self.size = 0 self.buckets = [None] * self.capacity def _hash(self, key): return hash(key) % self.capacity def _resize(self): old_buckets = self.buckets self.ca
🌐
CodeSignal
codesignal.com › learn › courses › revision-of-python-hashmaps-and-their-use-in-practice › lessons › essentials-of-hashmaps-in-python
Essentials of HashMaps in Python
Imagine dozens of toys in a box. If each toy had a unique label (the key), you could directly select a toy (the value) using the label. No rummaging required — that's the power of HashMaps! Today, we'll understand HashMaps and learn how to implement them in Python.
🌐
Medium
medium.com › @philip.smalls86 › building-a-custom-hashmap-in-python-an-in-depth-look-f477fd2cbea8
Building a Custom HashMap in Python: An In-Depth Look | by Philip Smalls | Medium
October 11, 2024 - Hashmaps (or hash tables) are a key component of computer science, offering an efficient way to store key-value pairs. Their main strength is that they allow for fast lookups, insertions, and deletions by leveraging the power of hashing. In Python, the built-in dict type already implements a hash table, but in this blog, we'll explore building a custom HashMap from scratch using the concept of chaining to resolve collisions.
🌐
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
Hash maps are a common data structure used to store key-value pairs for efficient retrieval. A value stored in a hash map is retrieved using the key under which it was stored · Hash map data structures use a hash function, which turns a key into an index within an underlying array.
🌐
Swovo
swovo.com › blog › python-hashmap-a-comprehensive-guide-to-hash-tables
Python Hashmap: A Comprehensive Guide to Hash Tables - Swovo
Dictionaries in Python, also known as hashmaps, are versatile data structures that allow you to store and retrieve data efficiently. You can create dictionaries in two primary ways: using curly braces ({}) or the built-in dict() function. ... Using Curly Braces- When creating a dictionary with curly braces, you can directly define key-value pairs. For example, you can create a dictionary of employee IDs like this:
🌐
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 keys of a dictionary in Python are generated by a hashing function. 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. Moving ahead, let’s see the difference between the hash table and hashmap ...
🌐
Scaler
scaler.com › home › topics › hashmap in python
Hashmap in Python - Scaler Topics
January 29, 2024 - A hashmap, synonymous with a dictionary, efficiently links keys to their associated values. Essential in Python, understanding dictionaries equips one to utilize hashmaps effectively. Operating as indexed structures, hashmaps employ hash functions to determine storage locations within an array of buckets.
🌐
CodeSignal
codesignal.com › learn › courses › revision-of-python-hashmaps-and-their-use-in-practice › lessons › hashmaps-in-action-solving-real-world-problems-in-python
HashMaps in Action: Solving Real-World Problems in Python
HashMaps are beneficial in real-life applications, such as the ones mentioned above, due to their ability to rapidly retrieve data with unique keys and efficiently handle larger datasets. Let's understand their efficiency with some actual examples. Solving Real-World Task 1: Cataloging Books in a Library · Suppose you're asked to manage the cataloging of books in a library. In Python...