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 trialDavid Agumya
12,285 PointsI answered the question correctly but the evaluation is incorrect. How can I challenge it
question is to produce all the even indexes in an iterable in reverser order.
my code was result = iterable[::-2]
how is this wrong ?
def first_4(word):
return word[:4]
def first_and_last_4(word):
first = word[:4]
last = word[len(word)-4:]
first.extend(last)
return first
def odds(itr):
return itr[1::2]
def reverse_evens(itr):
return itr[::-2]
1 Answer
james south
Front End Web Development Techdegree Graduate 33,271 Pointsthe way it is wrong is that you are getting every other index going backwards with [::-2], but depending on the length of the word, and thus whether the last index is odd or even, you may or may not be getting the even indices. to use [::-2] you should test for length and cut off the last index if odd; alternatively, you can slice every other index from the beginning, then reverse.
David Agumya
12,285 PointsDavid Agumya
12,285 PointsOkay, thanks I get it now.