Free tools Windows power users keep installed
One-click scans. No signup required.
Python dictionaries have no append() method. To add a key-value pair, assign a value with d[key] = value. If the key already exists, the assignment replaces its value; it does not create a duplicate key.
append() is for a list value, not a dictionary
A dictionary maps unique keys to values. That means adding an item to the dictionary means creating a key-value pair, which you do with assignment. The name “append” is often used informally to mean “add,” but calling append() on a dictionary raises an error because dictionaries do not provide that method. See the Python dictionary documentation.
As an Amazon Associate I earn from qualifying purchases.
scores = {}
scores["Ada"] = 95
scores["Ada"] = 98 # Replaces 95; it does not add another "Ada" entry
Add one key-value pair
Use square-bracket assignment when you want a key to point to a value:
settings = {"theme": "light"}
settings["language"] = "en" # Adds a new key
settings["theme"] = "dark" # Replaces the existing value
Dictionary keys are unique. Assigning to a key that is already present updates the value associated with that key.
#1 Best Overall
Add or update several pairs
Use update() to apply pairs from another mapping or an iterable of key-value pairs. It changes the dictionary in place and returns None; matching keys are overwritten.
settings.update({"theme": "dark", "language": "en"})
Collect multiple values under one key
If your goal is to keep several values associated with one key, make the dictionary value a list. Then call append() on that list—not on the dictionary.
Rank #2
groups = {}
groups.setdefault("fruit", []).append("pear")
groups.setdefault("fruit", []).append("plum")
# {"fruit": ["pear", "plum"]}
setdefault(key, default) returns the existing value for a key, or inserts and returns default when the key is absent. Here, it provides a list that can receive the new item.
When you repeatedly build lists for keys that may not exist yet, collections.defaultdict(list) is another option:
from collections import defaultdict
groups = defaultdict(list)
groups["fruit"].append("pear")
groups["fruit"].append("plum")
Use setdefault() when you want to keep a regular dictionary explicit; use defaultdict(list) when automatic list creation for missing keys suits the code. Both patterns are documented in the Python collections documentation.
Read a missing key without inserting it
Square-bracket lookup raises KeyError when the key is absent. If absence is expected and you want a fallback value without changing the dictionary, use get():
value = settings.get("font", "system")
If "font" is missing, value is "system"; get() does not add a "font" entry. By contrast, setdefault("font", "system") would insert that key when it is absent.
Recommended Free Tools
Choose the operation that matches the task
| What you want | Use | Effect |
|---|---|---|
| Add or replace one pair | d[key] = value |
Creates the key if absent; replaces its value if present. |
| Apply several pairs | d.update(other) |
Mutates d; overwrites colliding keys. |
| Insert a fallback only if absent | d.setdefault(key, default) |
Returns the existing value or inserts and returns the default. |
| Collect repeated items under one key | d[key].append(item) |
Appends to a list stored as that key’s value; initialize the list with setdefault() or defaultdict(list) if needed. |
| Read with a fallback, without inserting | d.get(key, default) |
Returns the stored value or the fallback; leaves the dictionary unchanged. |
What happens to dictionary order?
Current Python dictionaries preserve insertion order. Updating an existing key does not move it; deleting a key and then inserting it again places it at the end. See the dictionary type documentation for these ordering details.
Quick Recap
Best Value
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




