Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Python Collections (2016, retired 2019) Lists Removing items from a list

William Harpley
William Harpley
20,792 Points

messy_list Step 2 error

Not sure why I keep getting this error on step 2 of the Python messy_list challenge.

AttributeError: 'NoneType' object has no attribute 'copy'

lists.py
messy_list = ["a", 2, 3, 1, False, [1, 2, 3]]
messy_list = messy_list.insert(0,messy_list.pop(3))
loop_list = messy_list.copy()
for item in loop_list:
    if type(item) is not int:
        messy_list.remove(item)

1 Answer

Grigorij Schleifer
Grigorij Schleifer
10,365 Points

Hi William, your code works just fine in the workspace. I removed the assignment part at the second line and could pass the challenge. To be honest I have no clue why it didn't pass in the first place. But the interpreter is sometimes very picky. Maybe it doesn't like the new colors and is upset :smile:

messy_list = ["a", 2, 3, 1, False, [1, 2, 3]]
messy_list.insert(0,messy_list.pop(3)) # assignment removed

loop_list = messy_list.copy()
for item in loop_list:
    if type(item) is not int:
        messy_list.remove(item)

I hope that helps

William Harpley
William Harpley
20,792 Points

I came back to this a few days later, and the interpreter like your code better. Tricky little interpreter... appreciate the help :)

Grigorij Schleifer
Grigorij Schleifer
10,365 Points

Ha ha, oh yes ... the interpreter is a drama queen :smile: