Last modified: Dec 12, 2025 By Alexander Williams

Fix Python AttributeError: 'list' object has no attribute 'update'

Python errors can stop your code. This guide explains a common one.

You will see the AttributeError: 'list' object has no attribute 'update'.

This happens when you try to use a dictionary method on a list.

We will show you why it happens and how to fix it easily.

Understanding the Error

The error message is very specific. It tells you the problem.

You have a list object. You tried to call the update method on it.

But lists in Python do not have an update method. This method belongs to dictionaries.

You are likely confusing list and dictionary operations.

Let's look at a simple example that causes this error.


# This code will cause an AttributeError
my_list = [1, 2, 3]
my_list.update([4, 5])  # Trying to use dict method on a list
    

AttributeError: 'list' object has no attribute 'update'
    

Why Lists Don't Have 'update'

Python data types have specific methods. These methods define what you can do.

The update method is for dictionaries. It merges one dictionary into another.

Lists are for ordered sequences of items. They use methods like append or extend.

Mixing these up is a common mistake for beginners. It's easy to do.

Similar confusion can cause errors like 'dict' object has no attribute 'append'.

Common Causes and Fixes

Let's explore typical scenarios. We will provide the fix for each one.

1. Confusing Lists with Dictionaries

You might think your variable is a dictionary. But it's actually a list.

Check your variable's type. Use the type() function for this.

Here is an example of the confusion and the correction.


# Incorrect: Treating a list like a dict
config_data = ['host', 'localhost', 'port', 8080]
# config_data.update({'debug': True})  # This would error

# Correct: Define it as a dictionary from the start
config_data = {'host': 'localhost', 'port': 8080}
config_data.update({'debug': True})  # This works
print(config_data)
    

{'host': 'localhost', 'port': 8080, 'debug': True}
    

2. Intending to Use List.extend()

You probably want to add multiple items to a list. For this, use extend.

The extend method adds all items from an iterable to the list's end.

It is the list equivalent of a dictionary's update.


# The wrong way (causes error)
my_fruits = ['apple', 'banana']
# my_fruits.update(['orange', 'grape'])  # ERROR

# The right way: use extend()
my_fruits = ['apple', 'banana']
my_fruits.extend(['orange', 'grape'])
print(my_fruits)
    

['apple', 'banana', 'orange', 'grape']
    

3. Intending to Use List.append()

Maybe you want to add a single item. Use the append method for that.

append adds one object to the end of the list.

Remember, append adds the whole object, even if it's another list.


# Adding a single element
tasks = ['write', 'test']
tasks.append('deploy')  # Adds the string 'deploy'
print("After append:", tasks)

# Adding a list as a single element (nested list)
tasks.append(['monitor', 'log'])
print("After appending a list:", tasks)
    

After append: ['write', 'test', 'deploy']
After appending a list: ['write', 'test', 'deploy', ['monitor', 'log']]
    

4. Variable Reassignment Confusion

Your variable might change type. This can happen later in your code.

You start with a dictionary. Then you reassign a list to the same variable name.

Later, you try to use update on it, forgetting the change.

Always track your variable types. Use descriptive names to help.


# Start with a dict
settings = {'theme': 'dark'}
# ... later in code, accidentally reassign to a list
settings = ['dark', 'large']
# ... even later, trying to update (ERROR)
# settings.update({'language': 'en'})  # Fails!

# Fix: Be consistent with variable types.
# Or check type before calling methods.
if isinstance(settings, dict):
    settings.update({'language': 'en'})
else:
    print("settings is not a dict, it's a", type(settings))
    

How to Debug This Error

Follow these steps when you see this AttributeError.

First, check the variable type. Use print(type(your_variable)).

Second, review your code. Look for where the variable was created or changed.

Third, decide what you really want to do. Add items or merge key-values?

Finally, choose the correct method for your data type.

This process helps with many similar errors, like 'list' object has no attribute 'lower'.

Key Differences: List vs Dictionary Methods

Knowing common methods prevents errors. Here is a quick reference.

List Methods:append(item), extend(iterable), insert(index, item), remove(item).

Dictionary Methods:update(other_dict), get(key), keys(), items().

Using items() on a string causes 'str' object has no attribute 'items'.

Always match the method to the correct data structure.

Best Practices to Avoid the Error

Use clear variable names. Names like user_list or config_dict help.

Initialize variables properly. Know if you need a list or a dict from the start.

Use an IDE or editor with code completion. It suggests correct methods.

Read the error traceback carefully. It points to the exact line of failure.

Practice with Python's interactive shell. Test methods on different types.

Conclusion

The AttributeError about 'update' on a list is a type confusion error.

You tried to use a dictionary method on a list object.

The fix is to use the right method for your data type.

Use extend() to add multiple items to a list.

Use append() to add a single item to a list.

If you need key-value pairs, ensure you are using a dictionary.

Understanding these basics makes you a better Python programmer.

It also helps you fix related errors quickly and confidently.