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) Slices Slice Functions

Siddharth Pande
Siddharth Pande
9,046 Points

cant solve this one

return only odd numbers from list

slices.py
def first_4(listy):
    return listy[:4]
def first_and_last_4(listy):
    first_4 = listy[:4]
    last_4 = listy[-4:]
    return first_4 + last_4
def odds(oddy):

1 Answer

Brandon Spangler
Brandon Spangler
8,756 Points

Here is a hint: The % operator will return the remainder after division by a certain number. For example, if I wanted to see what the remainder after division by 2 is, I would use number%2. Why is this important? Every integer is either even or odd, even numbers will have a remainder of 0 after division by 2. So, if integer%2 == 0 then I know integer is even. See if you can figure the challenge out now that you know this.

I hope this helps!