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

victor E
victor E
19,145 Points

I could swear I am doing this correctly but it is giving me a hard time...

this is what I am using for these challenges... what am I missing? also, on the next one it asks to return the value for an iterable showing only odd numbers so I typed:

def odd(iterable): return iterable[1::2]

this way it can begin with 1, leave the zero out and skip every number to return only odd numbers.

what am I missing?

def first_4(iterable):
    return iterable[:4]

def first_and_last_4(iterable):
    return iterable[:4][-4:]

2 Answers

Hey Victor,

I'm assuming it wants you to return the first and last 4 of iterable as a single list of numbers or items. The way i would do it is return iterable[:4] + iterable[-4:]. This will return one list with first four items of iterable and last four items.

victor E
victor E
19,145 Points

Thank you very much!

Viraj Deshaval
Viraj Deshaval
4,874 Points

Yes whatever you did for odd numbers was correct. The only thing you were missing is concatenation for finding first 4 and last 4 numbers. Your logic was absolutely correct. Best Practice is to add the brackets '()'. So, return (iterable[:4] + iterable[-4:]) Remember slices work like slices[start:stop:step]