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

Michael Pastran
Michael Pastran
4,727 Points

first_and_last_4 challenge

i dont get how to get this. the way that i am doing it, is im creating two difference slices but thats not what is asking me to do. i have to slice the first 4, and the last 4, all in one slice

slices.py
def first_4(str):
  return str[:4]

def odds(str):
  return str[1::2]

def first_and_last_4(str):
  return str[0:4],str[-4:]

1 Answer

Can you try 2 slices, then concatenate them with the + operator?

Michael Pastran
Michael Pastran
4,727 Points

didnt even think about that. the instructions on these things are always so vauge. just did

return str[:4] + str[-4:]

thanks for the idea Brian