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 trialBapi Roy
14,237 PointsWhat is wrong with my code
messy_list = ["a", 2, 3, 1, False, [1, 2, 3]] messy_list2 = ["a", 2, 3, 1, False, [1, 2, 3]]
Your code goes below here
for i in messy_list2: if type(i) is not int: messy_list.remove(i)
Output need to be a list (messy_list) with integer
messy_list = ["a", 2, 3, 1, False, [1, 2, 3]]
messy_list2 = ["a", 2, 3, 1, False, [1, 2, 3]]
# Your code goes below here
for i in messy_list2:
if type(i) is not int:
messy_list.remove(i)
print messy_list
6 Answers
Kenneth Love
Treehouse Guest Teacherprint()
, not print
.
Bakthyar Syed
Courses Plus Student 884 Pointsmessy_list.insert(0,messy_list.pop(3)) for item in messy_list: if type(item) is not int: messy_list.remove(item) messy_list.pop(-1)
Bapi Roy
14,237 PointsIn my shell, I am getting no error. But is Treehouse's Challenge Task page I am getting "Oops! " message.
Kenneth Love
Treehouse Guest TeacherWhen I run your code, with the print
fixed, I get a very specific error message in the code challenge. You've missed a step in the instructions.
Bapi Roy
14,237 Points@keenethlove you were right, I was missing a point. Thank you
David Leal
1,990 Pointshey Kenneth Love i am wondering why we cant do this messy_list = ["a", 2, 3, 1, False, [1, 2, 3]] for i in messy_list: if type(i) is not int: messy_list.remove(i) i mean why we have to use a second list
Bapi Roy
14,237 Points@Kenneth It is working fine in my system shell, yet I am not able to pass the challenge.
Kenneth Love
Treehouse Guest TeacherWhat error message are you getting?
Bapi Roy
14,237 PointsBapi Roy
14,237 PointsThank you for your reply.
I am still getting "Oops! " in Challenge Task.
The task is "Great! Now use .remove() and/or del to remove the string, the boolean, and the list from inside of messy_list. When you're done, messy_list should have only integers in it."
Kenneth Love
Treehouse Guest TeacherKenneth Love
Treehouse Guest TeacherYou must still have some values in there you're not expecting. Try it out in your Python shell on your computer or in Workspaces.