TryBugHunt

AttributeError: 'list' object has no attribute

AttributeError: 'list' object has no attribute in Python means you called a method on a list that belongs to another type, such as .split(), .strip(), .lower() (strings) or .keys() (dictionaries).

PythonPattern: Type errors

How do I fix AttributeError: 'list' object has no attribute?

To fix AttributeError: 'list' object has no attribute in Python, locate the line causing the error and check the values right before it runs. Most occurrences happen because of calling a string method on a list of strings. Apply a defensive check or safe fallback, make sure collections or objects exist before access, and verify return values from upstream functions.

1. Inspect bounds & typesPrint or inspect collection sizes and verify variables are not empty or None/undefined.
2. Guard with safe accessUse optional chaining (?.), dictionary get(), or guard conditions before dereferencing.
3. Trace upstream originsFind where the value was instantiated or returned rather than only patching the symptom.

What does AttributeError: 'list' object has no attribute mean?

Python lists have methods like .append(), .pop(), and .extend(), but do not have string, dictionary, or set methods. This error often surfaces when a function returns a list of items and you accidentally call a string method on the entire list instead of iterating over it.

Why does AttributeError: 'list' object has no attribute happen?

1. Calling a string method on a list of strings

split() or lower() must be called on individual strings, not the containing list.

Breaks

words = ["HELLO", "WORLD"]
clean = words.lower()

Works

words = ["HELLO", "WORLD"]
clean = [w.lower() for w in words]

2. Using JavaScript's .push() instead of Python's .append()

Python lists use .append(item), not .push(item).

Breaks

numbers = [1, 2, 3]
numbers.push(4)

Works

numbers = [1, 2, 3]
numbers.append(4)

3. Calling .keys() or .values() on a list

Only dictionaries have keys() and values().

Breaks

rows = [{"id": 1}, {"id": 2}]
ids = rows.keys()

Works

rows = [{"id": 1}, {"id": 2}]
ids = [r["id"] for r in rows]

How to find it in your own code

Check the type of the variable with type(x). If it is a list of strings or dictionaries, use a list comprehension or loop to apply the method to each item individually.

Try it: fix this bug

easy

format_price(5) crashes: TypeError: can only concatenate str (not "int") to str.

def format_price(amount):
    return "$" + amount
Open with hintsRuns in your browser. No account needed.

More challenges with this error

Each of these challenges runs into this error or pattern. Find the bug and fix it in your browser โ€” no install, no account needed.

Still not sure why yours breaks?

Paste it into the visualizer and watch it run line by line, with every variable at every step. Free, and it runs in your browser.

Related error guides

View all type errors โ†’