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 trialAri Misha
19,323 Pointscan someone points out the issue with my code 'coz treehouse editor keeps saying "try again"
Its the 4th task of slice.py challenge where you have to return reverse of even indexed array using splice operator. Here is my code :
def first_4(iterable):
return iterable[:4]
def first_and_last_4(another_iterable):
return another_iterable[:4] + another_iterable[-4:]
def odds(more_iterable):
return more_iterable[1::2]
def reverse_evens(just_stop_with_slices):
just_stop_with_slices = just_stop_with_slices.sort().reverse()
if len(just_stop_with_slices[]) % 2 == 0:
return just_stop_with_slices[::2]
else:
return just_stop_with_slices[1::2]
1 Answer
Krishna Pratap Chouhan
15,203 PointsI think author dont want you to use reverse and definitely do not sort the list as it will change the sequence.
HINT: find item with even index and then reverse the string
Solution is .
.
.
def first_4(iterable):
return iterable[:4]
def first_and_last_4(another_iterable):
return another_iterable[:4] + another_iterable[-4:]
def odds(more_iterable):
return more_iterable[1::2]
def reverse_evens(just_stop_with_slices):
return (just_stop_with_slices[::2])[-1::-1]