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

SUDHARSAN CHAKRAVARTHI
PLUS
SUDHARSAN CHAKRAVARTHI
Courses Plus Student 2,434 Points

list manipulation

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

Your code goes below here

the_list.insert(0,the_list.pop(3)) the_list.remove('a'); the_list.remove(False) the_list.remove([1,2,3]) del the_list [:]

Like to know what's the wrong in above code?.

And i tried below code too:

Your code goes below here

the_list.insert(0,the_list.pop(3)) the_list.remove('a'); the_list.remove(False) the_list.remove([1,2,3]) the_list.remove(2) the_list.remove(3) the_list.remove(1)

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

# Your code goes below here
the_list.insert(0,the_list.pop(3))
the_list.remove('a');
the_list.remove(False)
the_list.remove([1,2,3])
del the_list [:]

6 Answers

Andrew K
Andrew K
13,774 Points

Hi there Sudharsan, Your first four lines of code are just fine, but the final step of the challenge asks you to use the extend function to make your list contain a range from 1 to 20.

Tara Edwards
Tara Edwards
6,521 Points

So, does that mean that I do not have to determine type? Because I have made an elaborate '''if''' statement based on the result of '''type(item in list)'''.

Kenneth Love
Kenneth Love
Treehouse Guest Teacher

Tara Edwards you do not have to worry about types to complete this challenge. You can, of course, but you're making it harder than it has to be.

Kenneth Love
STAFF
Kenneth Love
Treehouse Guest Teacher

What do you think the del the_list [:] line is doing?

SUDHARSAN CHAKRAVARTHI
PLUS
SUDHARSAN CHAKRAVARTHI
Courses Plus Student 2,434 Points

i used to delete remaining contents in the list. Since i missed to delete the list [1 2 3 ] inside the list. i was given error message. Thank You very much.

Kenneth Love
Kenneth Love
Treehouse Guest Teacher

del the_list [:] would delete a copy of the_list.

SUDHARSAN CHAKRAVARTHI
PLUS
SUDHARSAN CHAKRAVARTHI
Courses Plus Student 2,434 Points

del the_list [:] will delete only the contents right?. or the even it deletes the list "the_list". Confirm my understanding.

Kenneth Love
Kenneth Love
Treehouse Guest Teacher

It will delete the contents of the list, yes. You don't need to delete the contents of the list, though.

Tony McCabe
Tony McCabe
4,889 Points

the_list = ["a", 2, 3, 1, False, [1, 2, 3]] love = the_list.pop(3) the_list.insert(0,love) the_list.remove([1, 2, 3]) the_list.remove(False) del the_list[1] the_list.extend(range(3,21)) this code does not seem to be working... Say's bummer???

SUDHARSAN CHAKRAVARTHI
SUDHARSAN CHAKRAVARTHI
Courses Plus Student 2,434 Points

Yes. i solved it with the help of forum members. now forgot the question. can you ping me the task needs to be completed on the given list. so that i can help my best...

Example code : the_list.insert(0,the_list.pop(3)) the_list.remove('a') the_list.remove(False) del the_list[:]

Modify the code according to your task.