Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Python Collections (Retired) Slices Slice Functions

Philip Ondrejack
Philip Ondrejack
4,287 Points

Bug 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.

slices.py
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
Stone Preston
42,016 Points
list1 = [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
Philip Ondrejack
4,287 Points

I 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."

Philip Ondrejack
Philip Ondrejack
4,287 Points

Oh I see, that makes sense but isn't spelled out very clearly. This has tripped me up on more than one of these challenges.