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 trialPhilip Ondrejack
4,287 PointsBug In The System
Take a look at the code attached and the output. Something is definitely off here. Oklahoma
is not anywhere on this challenge.
list1 = [1,2,3,4]
def first_4(list1):
return list1[0:4]
list2 = [2,3,4,5,6,7]
def odds(list2):
return list2[0::2]
2 Answers
Stone Preston
42,016 Pointslist1 = [1,2,3,4]
def first_4(list1):
return list1[0:4]
in the above code the list1 = [1,2,3,4] creates a variable that never gets used. the parameter defined in def first_4(list1):
is a local variable scoped to the function, it does not reference the list1 variable defined above.
the challenge does not ask you to create any variables, just define the functions. then, to test the functions, it calls them passing in its own list argument (a list containing the characters of "oklahoma" apparently)
Philip Ondrejack
4,287 PointsOh I see, that makes sense but isn't spelled out very clearly. This has tripped me up on more than one of these challenges.
Philip Ondrejack
4,287 PointsPhilip Ondrejack
4,287 PointsI understand what you're saying but given the nature of what we're doing that needs to be explained better. Maybe as: "Don't worry about writing a list, just define the function and we'll pass in the list for you. You're goal is only to be able to slice lists in the correct places."