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 (Retired) Lists Redux Manipulating Lists

Nancy Melucci
PLUS
Nancy Melucci
Courses Plus Student 35,157 Points

Can't figure this code challenge out....

I am getting the error message AttributeError: 'int' object has no attribute 'insert'

Running it in PyCharm as a test before using the Code Challenge area.

Any hints would be appreciated. I've tried it several different ways....nothing works. Thanks.

lists.py
the_list = ["a", 2, 3, 1, False, [1, 2, 3]]

# Your code goes below here

the_list_1 = the_list.pop(3).insert(the_list(0))

4 Answers

Juan Martin
Juan Martin
14,335 Points

Hello my friend!

You can do it step by step, and also remember that "insert" takes 2 arguments (first: index, second: value). Here's an example of how you can do it:

the_list = ["a", 2, 3, 1, False, [1, 2, 3]]

# Your code goes below here

value = the_list.pop(3)
the_list.insert(0, value)

Hope this works for you :)

Hi Nancy, You don't need to create a new variable. You can simply insert the value of the_list.pop(3) into insert().

the_list.insert(0, the_list.pop(3))

You need to use 0 as the first argument in the insert() function to indicate the index where the value returned by pop() will be assigned.

Juan Martin
Juan Martin
14,335 Points

That's correct :) but if you're new to Python, I think it's a better way to explain it step by step more explicitly using variables :P

Nancy Melucci
PLUS
Nancy Melucci
Courses Plus Student 35,157 Points

These are both good but I used Juan's solution. I figured out part 2 with my own tiny little mind but part 3 is not working and it's killing the first two stages. The frustrating thing is that it works in PyCharm one of the IDEs I use. But it fails in the auto-grader here.

value = the_list.pop(3)
the_list.insert(0, value)
del the_list[1]
del the_list[3]
del the_list[3]
the_list.extend([4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20])
Kenneth Love
Kenneth Love
Treehouse Guest Teacher

Your code just passed all three steps for me. What error are you getting?

Nancy Melucci
PLUS
Nancy Melucci
Courses Plus Student 35,157 Points

Ha ha...it just passed for me too. Maybe it was just feeling cranky. Or (at 4:50AM PST) I hit some key I should not have hit, trying to enter a correct solution....thanks Kenneth!