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 (2016, retired 2019) Lists Pop

Anthony Grodowski
Anthony Grodowski
4,902 Points

Challanged myself to complete the challange in a harder way but smth went wrong. Can you tell, what?

The code returns messy_list_2 not in a way I want to (instead of removing not-int items it just changes positions of the items)

Here's my code:

https://w.trhou.se/v55jua39c2 (program2.py file)

TIA <3

1 Answer

Steven Parker
Steven Parker
231,275 Points

Logic operators can be used to combine complete comparison expressions, but not parts of them. So a correct way to express your test on line 11 would be:

        if messy_list[0] == 1 or messy_list[0] == 2 or messy_list[0] == 3:

You can also do it more compactly without logic using a list and the membership operator ("in") this way:

        if messy_list[0] in [1,2,3]: