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!
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
Kyler Aagard1,331 Points
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.
def first_4(iterable): iterable = list(input("Input something. ")) first_4_items = iterable[:4] return first_4_items
Steven Parker224,873 Points
The iterable is passed to your function as an argument. You won't need to "input" anything!
David Lahoud1,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])