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

kushagra jain
PLUS
kushagra jain
Courses Plus Student 2,563 Points

challenge task 1of 4

first_4 problem

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

2 Answers

Alexandra Barnett
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Alexandra Barnett
Front End Web Development Techdegree Graduate 46,473 Points

Hi Kushagra! You almost have it! When you sliced the iterable, you didn't assign it to a variable before returning so, you can either assign the slice to a variable and then return the variable or return the slice like so:

def first_4(iterable):
    a_variable = iterable[0:4]
    return a_variable
def first_4(iterable):
    return iterable[0:4]

Hope this helps! Let me know if you have any questions :)