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

George Lugo
seal-mask
.a{fill-rule:evenodd;}techdegree
George Lugo
Python Web Development Techdegree Student 922 Points

i don't understand why my code is wrong

first_4 = ['john', 'calli', 'smith', 'michael','kelsey', 'cramer', ' george'] first_4[:5]

slices.py
first_4 = ['john', 'calli', 'smith', 'michael','kelsey', 'cramer', ' george']
first_4[:5]

2 Answers

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,441 Points

The challenge asks you to define a function. It should include a return statement. Something of the format:

def first_4(container):
    return <your slide code here>

Post back if still stuck. Good luck!!!

Stuart Wright
Stuart Wright
41,120 Points

[:5] actually selects the first 5 elements, not 4:

Element 0, element 1, element 2, element 3 and element 4.

Which part of the challenge are you trying to answer? Even if you change the slice to [:4] instead of [:5] it doesn't look like you are storing the result anywhere.