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 trialBrandon Harrison
1,283 Pointsmy function to return the first 4 item in an iterable will not work.
What am I missing? should I just give up on this coding thing at this point since I have to get help on these stupid things that seem so freaking simple?
def first_4(iterable):
return iterable[0,3]
Jeremy Hill
29,567 Pointsdef first_4(iterable):
return iterable[0:4]
1 Answer
Cindy Lea
Courses Plus Student 6,497 PointsThe return should look like this:
return iterable[0:4]
You forgot colon & need the number 4
Jeremy Hill
29,567 PointsYep it's all about remembering all of the syntax- I even forgot that it requires a colon vs. a comma. I've been working on java more so than Python lately ;)
Jeremy Hill
29,567 PointsJeremy Hill
29,567 PointsI believe when you do slices you put the second argument one number past what you want the last number to be, so try [0, 4]. It should add everything up to but not including the 4 index.