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

William Harpley
William Harpley
20,772 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,352 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,772 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,352 Points

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