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

Something's not clicking, please help!

I need to create a function to return first four values of the given iterable. Where's a mistake?

slices.py
def first_4(my_word):
    x = list(my_word)
    first_four = x[:4]    

3 Answers

Steven Parker
Steven Parker
231,269 Points

:point_right: It looks like you forgot the return statement.

Your value should be good, but you need to return it to the caller.

Also, you can optionally save a step by applying your slice directly to the iterable argument (you don't need to convert it to a list first).

Chris Freeman
Chris Freeman
Treehouse Moderator 68,441 Points

Edged out again! ?Thanks for all your community support!!!

Thank you! I usually get stuck because of simple things :)

Emil Rais
Emil Rais
26,873 Points

You're converting the string to a list. You do not need to do that. The string itself is an iterable. You end up returning the first 4 characters of the word as a list of characters rather than as a string.

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,441 Points

You have it correct so far. The return statement is missing. It's needed to return the value first_four.

Post back if you need a bigger hint.

I got it, thanks!