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 trialJoe Law
5,040 PointsHELP needed - Challenge: Manipulating Lists
the_list = ["a", 2, 3, 1, False, [1, 2, 3]]
Your code goes below here
num = the_list.pop(3)
the_list.insert(0,1)
the_list.remove('a')
the_list.remove(2)
the_list.remove(3)
the_list.remove(bool(False))
the_list.remove([1, 2, 3])
the_list.extend(range(2,21))
1) Why the range is (2,21) instead of (2,20)? 2) Is the any better method to remove items rather than the one i used?
2 Answers
MUZ140889 Dephine Chenayi Chihota
6,766 Pointshie Joe. firstly for challenge 1, in order to do that in one step you can try combining your two steps like this.
new_list = the_list.insert(0,the_list.pop(3))
this line creates a new variable new_list that stores the updated list. we first use the .insert method, we want to insert our number at index 0 and what we want to insert is the 1 which we can obtain by using the pop like you did.
for challenge two we are told to remove the string, boolean, and list members of the_list. you did that quite well for the string and the list of numbers. you also didn't have to remove the 2 and 3, ist not stated in the question. you also didn't have to add the prefix bool because its already built in that is the language already knows that False is a bolean.
the_list.remove('a')
the_list.remove(False)
the_list.remove([1, 2, 3])
lastly we want to extend our list so that it contains only the numbers 1 through 20. NOTE our list already contains the numbers 1,2 and 3. now to add 4 to 20 we use
new_list = the_list.extend(range(4,21))
this we add the numbers 4 upto 21. hop this helps, don't hesitate to get back to me if it doesn't work.
Andy Manning
628 PointsHaha, I wasted so much time trying to do this in one in a loop! The simplest answer is always the best :)
Joe Law
5,040 PointsJoe Law
5,040 PointsThanks Dephine! Wooow, really thank you! :D
MUZ140889 Dephine Chenayi Chihota
6,766 PointsMUZ140889 Dephine Chenayi Chihota
6,766 Pointsglad I could help