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 trialUllas Savkoor
6,028 PointsUnable 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]
def first_and_last_4(itreable):
list1 = iterable[:4]
list1 = list1 + iterable[-4:]
return list1
def first_4(iterable):
return iterable[:4]
3 Answers
Alexander Davison
65,469 PointsYou 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
~Alex
Congrats on thinking through the rest of the code
Ullas Savkoor
6,028 PointsThanks 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
Alexander Davison
65,469 PointsNo problem :)
Can you please provide a best answer? Thanks
natalia iaroslavskaia
7,293 Pointsdef first_and_last_4(arg): return arg[:4] + arg[-4:]