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 (Retired) Slices Slice Functions

Nicholas Hattwick
Nicholas Hattwick
2,697 Points

Python collections: first_4

I'm not sure what I'm doing wrong. Any advice would be appreciated. Thanks.

slices.py
list=range(6)

def first_4(list):
  return list[0:4]

2 Answers

Justin Iezzi
Justin Iezzi
18,199 Points

Hi Nicholas,

You don't need to create the list for this code challenge.

Just -

def first_4(list):
  return list[0:4]

Should pass the step. Try it out. :)

William Li
PLUS
William Li
Courses Plus Student 26,868 Points

list is a built-in function's name in Python, please refrain from using it as variable/parameter name, not only it's bad practice to do so, it can cause your program to have unpredictable behavior.

def first_4(li):
  return li[0:4]

this would be fine.

Nicholas Hattwick
Nicholas Hattwick
2,697 Points

thanks, I'll keep that in mind.