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 trialEvandro Luis Lima Pastor
1,061 PointsTask 1 not passes...
Hello,
Seriously, I have no idea how to solve this...
I can move the list item as requested. But to test the items, is another story. I know i have to do is something like:
- get the item from the list
- test if it is a number
- if not delete it from the list.
- store the number in a new list
But I just can't build the code... Any direction will be most appreciate.
Thanks!
the_list = ["a", 2, 3, 1, False, [1, 2, 3]]
# Your code goes below here
numero=the_list.pop(3)
the_list.insert(0,numero)
for item in the_list:
try:
int(item)
except:
item.delete()
2 Answers
Greg Kaleka
39,021 PointsHi Evandro,
I think you're over-thinking this!
All you have to do is tell Python to remove "a"
, False
, and [1, 2, 3]
. No loops, no type checking, etc.
Here's my solution:
the_list = ["a", 2, 3, 1, False, [1, 2, 3]]
# Your code goes below here
# Challenge Task 1 of 3
# Move the 1 to position 0. You can do this in one step with .pop() and .insert().
the_list.insert(0, the_list.pop(3))
# Challenge Task 2 of 3
# Use .remove() and/or del to remove the string, boolean, and list members of the_list.
the_list.remove("a")
the_list.remove(False)
the_list.remove([1, 2, 3])
Evandro Luis Lima Pastor
1,061 PointsHey Greg!
Jesus! So simple!!! I have problems to learn to program for YEARS. Maybe that's the reason...
Thank you for the tip Greg!
Greg Kaleka
39,021 PointsNo problem :)