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

Aishwarya Manicka Ravichandran
seal-mask
.a{fill-rule:evenodd;}techdegree
Aishwarya Manicka Ravichandran
Python Web Development Techdegree Student 3,679 Points

Getting an error : Did'nt get the values right for first_and_last_4

So, this is my code : new_list = [] def first_4(given_list): new_list = given_list[0:4:1] return new_list

def first_and_last_4(given_list): new_list_1 = given_list[-4:] new_list.extend(new_list_1) return new_list

list_given = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] first_4(list_given) first_and_last_4(list_given)

This code works perfectly in workspace but yet getting an error stating that values are'nt right. I cant understand why. Thanks in advance

slices.py
new_list = []
def first_4(given_list):
    new_list = given_list[0:4:1]
    return new_list

def first_and_last_4(given_list):
    new_list_1 = given_list[-4:]
    new_list.extend(new_list_1)
    return new_list

list_given = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
first_4(list_given)
first_and_last_4(list_given)

1 Answer

Your "first_and_last_4" function is only returning the last 4. Try calling "first_4" and adding the 2 lists together.

def first_and_last_4(given_list):
    return first_4(given_list) + given_list[-4:]