Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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