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

ABHINAV VERMA
ABHINAV VERMA
6,033 Points

list1 = list(range[20]) first_4 = list1[:4] What's wrong with this

list1 = list(range[20]) first_4 = list1[:4] What's wrong with this

slices.py
list1 = list(range[20])
first_4 = list1[:4]

2 Answers

Syntactically your range[20] should be range(20). Trying to do it the way you currently have it set up, you'll return a TypeError because a list object cannot be interpreted as an integer. though I'm not sure if that's the only reason you're not passing the Challenge. If this is all of your code for the Challenge, then the primary reason you would still not complete the task is because it is asking you to define a function first_4 which returns the first 4 values in the list, but instead you are creating a new list that contains those values and doing nothing with that list.

Challenge 1:

def first_4(whatever):
    return whatever[:4]