Recently, I was working on a project where I had to store multiple pieces of data for each customer, their city, orders, and loyalty points, all in one place. The challenge was simple: how do I store multiple values for a single key in a Python dictionary?
If you’ve ever tried to assign multiple values to one key in a Python dictionary, you’ll know that the latest value overwrites the previous one. That’s because Python dictionaries store key-value pairs, and each key must be unique.
But don’t worry, there are several clean and efficient ways to handle this. In this tutorial, I’ll show you four easy methods to create a Python dictionary with multiple values per key.
Method 1 – Use a List as a Dictionary Value
One of the simplest and most common ways to store multiple values per key is to use a list as the value. Lists are flexible, ordered, and easy to update.
When I first started using Python for data processing, this was my go-to approach because it’s intuitive and easy to maintain.
Here’s how you can do it:
customer_data = {
"John": ["New York", "Order #1023", "Gold Member"],
"Emma": ["Los Angeles", "Order #1045", "Silver Member"],
"Liam": ["Chicago", "Order #1056", "Platinum Member"]
}
# Adding a new value to an existing key
customer_data["John"].append("Referred by: Sarah")
# Printing the dictionary
for name, details in customer_data.items():
print(f"{name}: {details}")I have executed the above example code and added the screenshot below.

This approach is great when you know you’ll need to add or modify values often. You can use list methods like .append() or .extend() to update your data easily.
Tip: Always initialize the value as a list before appending to avoid KeyError.
Method 2 – Use set as Dictionary Value
Sometimes, I need to ensure that the values for each key are unique. For example, when tracking which states a product has been sold in, I don’t want duplicates.
That’s where Python sets come in handy. Sets automatically remove duplicates and are perfect for unordered collections of unique items.
Here’s a quick example:
product_sales = {
"Laptop": {"California", "New York", "Texas"},
"Headphones": {"Florida", "Texas", "California"},
"Smartwatch": {"Illinois", "California"}
}
# Adding a new state
product_sales["Laptop"].add("Nevada")
# Printing the dictionary
for product, states in product_sales.items():
print(f"{product} sold in: {states}")I have executed the above example code and added the screenshot below.

Using sets is efficient when you’re working with large datasets and want to prevent duplicates automatically. However, keep in mind that sets are unordered, so the order of insertion isn’t preserved.
Method 3 – Use defaultdict from the collections Module
When I started working with large datasets, I realized that manually checking if a key exists before adding values can be tedious. That’s when I discovered the defaultdict class from the collections module, a real time-saver!
A defaultdict automatically creates a default value for new keys, so you don’t have to initialize them manually.
Here’s how it works:
from collections import defaultdict
employee_projects = defaultdict(list)
# Adding multiple values per key
employee_projects["Alice"].append("Project A")
employee_projects["Alice"].append("Project B")
employee_projects["Bob"].append("Project C")
employee_projects["Bob"].append("Project D")
# Printing the dictionary
for employee, projects in employee_projects.items():
print(f"{employee}: {projects}")I have executed the above example code and added the screenshot below.

This method is my personal favorite because it’s clean, efficient, and eliminates the need for if key in dict checks. It’s especially powerful when you’re aggregating data from files, APIs, or databases.
Method 4 – Use a Dictionary of Dictionaries
In more complex Python applications, I often need to store structured data, like user profiles or product details, where each key has multiple attributes.
In such cases, a dictionary of dictionaries is a great choice.
Here’s an example:
user_profiles = {
"user_001": {"name": "Michael", "city": "Seattle", "membership": "Gold"},
"user_002": {"name": "Sophia", "city": "Boston", "membership": "Silver"},
"user_003": {"name": "Ethan", "city": "Dallas", "membership": "Platinum"}
}
# Accessing nested values
print(user_profiles["user_001"]["city"])
# Adding a new key-value pair inside a nested dictionary
user_profiles["user_002"]["email"] = "sophia@example.com"
# Printing all user profiles
for user_id, details in user_profiles.items():
print(f"{user_id}: {details}")I have executed the above example code and added the screenshot below.

This approach gives you more control and structure, especially when working with JSON-like data. It’s also easy to serialize and store in a database or file.
Method 5 – Use Tuples as Dictionary Values
Sometimes, I prefer using Python tuples instead of lists when I want to store multiple values that should not change. Tuples are immutable, which means once created, their contents cannot be modified.
Here’s an example:
employee_info = {
"E001": ("John Doe", "Finance", "New York"),
"E002": ("Emma Smith", "Marketing", "Chicago"),
"E003": ("Liam Brown", "IT", "San Francisco")
}
# Accessing tuple elements
for emp_id, info in employee_info.items():
print(f"Employee ID: {emp_id}, Name: {info[0]}, Department: {info[1]}, Location: {info[2]}")Tuples are ideal when you want to ensure data integrity, for example, storing employee details that shouldn’t be modified. They also use less memory compared to lists, which can be beneficial for large datasets.
Bonus Tip – Combine Methods for Flexibility
In real-world Python projects, I often combine these methods. For instance, you can use a defaultdict of sets to store unique values without worrying about initialization.
Here’s how:
from collections import defaultdict
# Combining defaultdict and set
customer_purchases = defaultdict(set)
# Adding data
customer_purchases["Alice"].add("Laptop")
customer_purchases["Alice"].add("Headphones")
customer_purchases["Bob"].add("Smartwatch")
customer_purchases["Bob"].add("Laptop")
# Printing the dictionary
for customer, items in customer_purchases.items():
print(f"{customer} purchased: {items}")This hybrid approach gives you both automation and uniqueness, a perfect balance for data aggregation tasks.
When to Use Each Method
| Method | Best For | Mutable | Preserves Order | Avoids Duplicates |
|---|---|---|---|---|
| List | General-purpose storage | ✅ | ✅ | ❌ |
| Set | Unique values | ✅ | ❌ | ✅ |
| defaultdict(list) | Large data aggregation | ✅ | ✅ | ❌ |
| Nested Dictionary | Structured data | ✅ | ✅ | ❌ |
| Tuple | Immutable data | ❌ | ✅ | ❌ |
Choosing the right method depends on your project’s needs. If you’re working with dynamic data, defaultdict is ideal. For read-only records, tuples or nested dictionaries make more sense.
So, these are five practical ways to create a Python dictionary with multiple values per key.
Each method has its strengths, from simple lists to powerful defaultdicts, and the best part is, you can mix and match them based on your use case.
Personally, I rely on defaultdict(list) for most of my data processing tasks because it keeps my code clean and efficient. However, for structured or immutable data, I often switch to nested dictionaries or tuples.
You may also like to read:
- Save a Matplotlib Plot as a Transparent PNG in Python
- Save NumPy Array as PNG Image in Python Matplotlib
- Save a Matplotlib Plot as PNG Without Borders in Python
- How to Save a Matplotlib Axis as PNG in Python

I am Bijay Kumar, a Microsoft MVP in SharePoint. Apart from SharePoint, I started working on Python, Machine learning, and artificial intelligence for the last 5 years. During this time I got expertise in various Python libraries also like Tkinter, Pandas, NumPy, Turtle, Django, Matplotlib, Tensorflow, Scipy, Scikit-Learn, etc… for various clients in the United States, Canada, the United Kingdom, Australia, New Zealand, etc. Check out my profile.