attributeerror: ‘list’ object has no attribute ‘values’

One of the most common errors that Python programmers encounter is the AttributeError: ‘list’ object has no attribute ‘values’.

In this article, we will discuss the solutions on how to solve it and what the causes of this error are.

Why the error attributeerror: list object has no attribute values occur?

The error message attributeerror: list object has no attribute values occur because you are trying to call the values() method on a list instead of a dictionary.

For example on how the error occurs:

# AttributeError: 'list' object has no attribute 'values'

name_list = [
    {'id': 1, 'fullname': 'Caren'},
    {'id': 2, 'fullname': 'Glenn'},
    {'id': 3, 'fullname': 'Elijah'},
    {'id': 4, 'fullname': 'Eliver'},
    {'id': 5, 'fullname': 'Jude'},
]
print(name_list.values())

If you run the code above the output will show an error:

C:\Users\Dell\PycharmProjects\pythonProject\venv\Scripts\python.exe C:\Users\Dell\PycharmProjects\pythonProject\main.py
Traceback (most recent call last):
File “C:\Users\Dell\PycharmProjects\pythonProject\main.py”, line 8, in
print(my_list.values())
AttributeError: ‘list’ object has no attribute ‘values’

We generate a list with five dictionaries, and we are trying to call the values() methods on the list. It will cause an error because values() is a dictionary method.

Also read:

These are the following solutions to solve the attributeerror: list object has no attribute values.

Solution 1: Use specific index to access a list element

The best way to solve this error is to access a list element at a specific index.

For example:

We will access the list element at index 0 before calling the dict.values() method.

name_list = [
    {'id': 1, 'firstname': 'Caren'},
    {'id': 2, 'firstname': 'Glenn'},
    {'id': 3, 'firstname': 'Elijah'},
    {'id': 4, 'firstname': 'Eliver'},
    {'id': 5, 'firstname': 'Jude'},
]
values = list(name__list[0].values())
print(values)

Output

C:\Users\Dell\PycharmProjects\pythonProject\venv\Scripts\python.exe C:\Users\Dell\PycharmProjects\pythonProject\main.py
[1, ‘Caren’]

If we will run the example code above it will print the id number 1 which is caren.

When you need to call the values() method on all dictionaries in the list, you can use a for loop function.

For example:

name_list = [
    {'id': 1, 'fullname': 'Caren'},
    {'id': 2, 'fullname': 'Glenn'},
    {'id': 3, 'fullname': 'Elijah'},
    {'id': 4, 'fullname': 'Eliver'},
    {'id': 5, 'fullname': 'Jude'},
]
for person in name_list:
    print(person.values())

Output:

C:\Users\Dell\PycharmProjects\pythonProject\venv\Scripts\python.exe C:\Users\Dell\PycharmProjects\pythonProject\main.py
dict_values([1, ‘Caren’])
dict_values([2, ‘Glenn’])
dict_values([3, ‘Elijah’])
dict_values([4, ‘Eliver’])
dict_values([5, ‘Jude’])

if you run the example above it will print all the name inside in the name_list such as caren, glenn, elijah, eliver and jude.

Let’s take a look at the other example:

dict = {'id': 1,  'name': 'Caren Manggana'}

print(dict.values())

Output:

C:\Users\Dell\PycharmProjects\pythonProject\venv\Scripts\python.exe C:\Users\Dell\PycharmProjects\pythonProject\main.py
dict_values([1, ‘Caren Manggana’])

This is the equality comparison between one dict.values() view and another, which will always return False. This also applies if you compare dict.values() to itself.

Solution 2: Find dictionary list before calling values()

If you need to find a dictionary in a list, you can use a generator expression.

For example:

name_list = [
    {'id': 1, 'fullname': 'Caren'},
    {'id': 2, 'fullname': 'Glenn'},
    {'id': 3, 'fullname': 'Elijah'},
    {'id': 4, 'fullname': 'Eliver'},
    {'id': 5, 'fullname': 'Jude'},
]

result = next(
    (item for item in name_list if item['fullname'] == 'Caren'),
    {}
)

print(result)

print(result.get('fullname'))
print(result.get('id'))

print(result.values())

Output:

C:\Users\Dell\PycharmProjects\pythonProject\venv\Scripts\python.exe C:\Users\Dell\PycharmProjects\pythonProject\main.py
{‘id’: 1, ‘fullname’: ‘Caren’}
Caren
1
dict_values([1, ‘Caren’])

The generator expression in the above example will look for a dictionary with a fullname that has the value of “caren” and will return the dictionary.

Frequently Asked Questions

What is Python AttributeError and what causes it?

AttributeError is raised when you access an attribute or method that doesn’t exist on the object. Most common cause: calling a method on None (NoneType has no attribute X). Other causes: typo in method name, wrong object type (str when you expected list), or using a feature removed in a newer library version. The error names exactly which type and which missing attribute.

How do I fix ‘NoneType object has no attribute’?

The variable you’re accessing is None, but you expected an object. Trace back to where it was assigned: a function returning None instead of an object (forgot to return), a database query returning no rows (Model.objects.first() returns None when empty), or an API call that failed silently. Safe pattern: if obj is not None: obj.method() OR use the walrus operator: if (obj := get_obj()): obj.method().

How do I check if an attribute exists before accessing it?

Use hasattr(obj, ‘attr_name’) for runtime check, or getattr(obj, ‘attr_name’, default) to get-with-default. For frequent attribute checks, consider type hints + mypy/pyright which catch most AttributeErrors at static-analysis time before runtime.

How do I prevent AttributeError from None values?

Three patterns: (1) Always validate function returns (if result is None: raise). (2) Use type hints with Optional[X] to make None-ability explicit. (3) Use the walrus operator + early return: if (val := get_val()) is None: return default; use val. Defensive coding around None-able returns prevents 90% of AttributeError in production.

Where can I find more AttributeError fixes?

Browse the AttributeError reference hub for 170+ specific fixes (NoneType, pandas, NumPy, sklearn, Selenium). For related errors see TypeError. For Python debugging fundamentals see Python Tutorial hub.

Conclusion

In conclusion, the “AttributeError: ‘list’ object has no attribute ‘values‘” error message is a common error that can occur when you are running Python program.

It shows that you are trying to use the “values” method on a list object, which does not have that attribute.

Adones Evangelista

Programmer & Technical Writer at PIES IT Solution

Adones Evangelista is a programmer and writer at PIES IT Solution, author of over 900 tutorials and error-fix guides at itsourcecode.com. Specializes in JavaScript, Django, Laravel, and Python error debugging covering ValueError, TypeError, AttributeError, ModuleNotFoundError, and RuntimeError, plus C/C++ and PHP capstone projects for BSIT students.

Expertise: JavaScript · Python · Django · Laravel · Error Debugging · C/C++  · View all posts by Adones Evangelista →

Leave a Comment