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

Unable to complete slice task 2 of 4 belonging to python collections.

I have create first_and_last4 function which return the first and last four item as a single value for my challenge, however when I click on check work it is unable to find the function it says Bummer! Couldn't find first_and_last_4 Below is the code:

def first_and_last_4(itreable):
    list1 = iterable[:4]
    list1 = list1 + iterable[-4:]
    return list1


def first_4(iterable):
    return iterable[:4]
slices.py
def first_and_last_4(itreable):
    list1 = iterable[:4]
    list1 = list1 + iterable[-4:]
    return list1


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

3 Answers

You misspelled iterable as itreable. Check your typos :)

This passes:

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

def first_and_last_4(iterable):
    list1 = iterable[:4]
    list1 = list1 + iterable[-4:]
    return list1

I hope this helps :grin:

:dizzy: ~Alex :dizzy:

Congrats on thinking through the rest of the code :smile: :sparkles: :+1: :sparkles:

Thanks for the solution: I was looking for mistakes in my syntax and in my logic , I missed the typo. Looking at the code now I can easily see the typo :D

No problem :)

Can you please provide a best answer? Thanks :sparkles:

natalia iaroslavskaia
natalia iaroslavskaia
7,293 Points

def first_and_last_4(arg): return arg[:4] + arg[-4:]