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

abhishek krishna vandadi
abhishek krishna vandadi
878 Points

isnt my code right?

isnt my code right?

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

# Your code goes below here
name_1=messy_list.pop(2)
messy_list.insert(0,1)

1 Answer

Sydney O'Reilly
Sydney O'Reilly
3,183 Points

There are two problems here. First, you're assigning the variable named name_1 the value of 3, (the item at index 2 in the messy_list) and popping that out of messy_list. The instructions say to remove the list item at index 3. And is it necessary to assign that value to a variable if you never use that variable in your code? Second, technically you're inserting the right value into the list at the right index, but instead of manually specifying the value of 1, couldn't you just instead insert the value of whatever happens when you pop the item at index 3? (what you did on your first line)