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

Alright, these tasks are a bit harder than the others so far in this course but I know you can do them! In this first o

i need a little push here please

slices.py
def first_4():
    return first_4(0:5)

3 Answers

Stuart Wright
Stuart Wright
41,118 Points

Ok you've made the appropriate corrections for the second two points on my list above, so it's just the first one that needs fixed. To better explain what I mean by passing a parameter to your function, here is a very basic function which simply returns the parameter with no changes:

def my_function(my_parameter):
    return my_parameter

The difference between the above and your function is that you should only return the first 4 elements of your parameter. Does that make sense?

It worked!! thank you

Stuart Wright
Stuart Wright
41,118 Points

Here are three hints to get you started:

  • your function needs to have a parameter which is an iterable, and you need to return the first four items of that iterable.
  • you need to use square brackets rather than parentheses for slicing.
  • the slice starting at 0 and ending before 5 is the first 5 elements, not 4.

Here is the corrections:

def first_4(1, 2, 3, 5, 7, 9, 3): return first_4[0:4]