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 trialMaiia Spivak
3,038 PointsSomething's not clicking, please help!
I need to create a function to return first four values of the given iterable. Where's a mistake?
def first_4(my_word):
x = list(my_word)
first_four = x[:4]
3 Answers
Steven Parker
231,269 PointsIt 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).
Emil Rais
26,873 PointsYou'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
Treehouse Moderator 68,441 PointsYou 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.
Maiia Spivak
3,038 PointsI got it, thanks!
Chris Freeman
Treehouse Moderator 68,441 PointsChris Freeman
Treehouse Moderator 68,441 PointsEdged out again! ?Thanks for all your community support!!!
Maiia Spivak
3,038 PointsMaiia Spivak
3,038 PointsThank you! I usually get stuck because of simple things :)