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

Why won't my iterable function work?

To me, line by line, this is 1) Creating a function with the iterable variable. 2) Getting input in the form of a list for the iterable variable. 3) Creating a copy of the iterable list with only items 1-4. 4) Returning the copy of the iterable list, which only has items 1-4 in it. I don't understand why this doesn't work.

slices.py
def first_4(iterable):
    iterable = list(input("Input something. "))
    first_4_items = iterable[:4]
    return first_4_items

2 Answers

Steven Parker
Steven Parker
229,744 Points

The iterable is passed to your function as an argument. You won't need to "input" anything!

David Lahoud
David Lahoud
1,408 Points

You just need to return the slice iterable not take input a solution for your code would look something like this: def first_4(iterable): return iterable[0:4]

and to check you can call the function and add different info into the parameters like so: first_4([1,2,3,4,5,6])