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

Can't combine my slices?

I'm working on part 3 of slices.py, and while I can get the first 4 and the last 4 items individually, I can't combine them to be returned as one. I have tried .extend() as shown, making 2 variables called first and last and trying to use .extend() that way, putting the two slices together in the brackets separated by a comma, using a plus between the two in bracket notation, and just setting them right next to each other [:4][-4]. Did I miss a lesson somewhere?

slices.py
def first_4(iti):
  return iti[:4]
def odds(iti):
  return iti[1::2]
def first_and_last_4(iti):
  return iti[:4].extend(iti[-4:])

1 Answer

Vittorio Somaschini
Vittorio Somaschini
33,371 Points

Hello Emma.

You can just put a plus between the two slices and you will be fine.

Vitto

Thank you! I realized that when I tried this the first time, I didn't put iti before my second bracket notation.