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 trialNoah Harness
1,383 PointsEliminate two items in a list with either one or both del. and .remove()
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.
messy_list = ["a", 2, 3, 1, False, [1, 2, 3]]
messy_list.insert(0, messy_list.pop(3))
# Your code goes below here
8 Answers
olegovich7
6,605 Pointsmessy_list = ["a", 2, 3, 1, False, [1, 2, 3]]
messy_list.insert(0, messy_list.pop(3))
messy_list.remove("a")
del messy_list[3]
del messy_list[3]
Murat Can Berber
3,238 Pointsmessy_list = ["a", 2, 3, 1, False, [1, 2, 3]]
# Your code goes below here
messy_list.insert(0, messy_list.pop(3))
i = 0
for letter in messy_list:
print(messy_list[i])
if isinstance(messy_list[i],( bool, str, list, tuple)):
messy_list.pop(i)
i += 1
messy_list.pop(-1)
## I tried to check item for type == list. but it doesnt work. i also tried use try catch item / item. hope this help
f4u57
6,743 Pointsmessy_list.remove("a")
messy_list.remove(False)
messy_list.remove([1, 2, 3])
Noah Harness
1,383 Pointsnevermind I spelled something wrong thanks man I really appreciate it haha
Billy Feighery
9,866 Pointsmessy_list = ["a", 2, 3, 1, False, [1, 2, 3]]
# Your code goes below here
messy_list.insert(0, messy_list.pop(3))
clean_list = []
for i in messy_list:
if (isinstance(i, int)) and not (isinstance(i, bool)):
clean_list.append(i)
print(clean_list)
messy_list = clean_list
It's not overly pretty, but it works.
Noah Harness
1,383 PointsHuh its not working for me. Its saying that part one is no longer working
Peshal Parajuli
1,452 Pointsimport numbers
messy_list = ["a", 2, 3, 1, False, [1, 2, 3]]
Your code goes below here
messy_list.insert(0, messy_list.pop(3))
messy_list = [x for x in messy_list if isinstance(x, numbers.Number)] del messy_list[3] print(messy_list)
Christopher Reynolds
2,817 Pointsas question:
why doesn't this work
messy_list = ["a", 2, 3, 1, False, [1, 2, 3]] messy_list.insert(0, messy_list.pop(3)) messy_list.remove(False) messy_list.remove("a") messy_list.remove([1, 2, 3])
Christopher Reynolds
2,817 Pointsnever mind,
sorry
Noah Harness
1,383 PointsNoah Harness
1,383 PointsYeah that isn't close to working dude
olegovich7
6,605 Pointsolegovich7
6,605 PointsWorkpaces python shell:
Code challenge:
Congrats, you've completed the challenge!