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 trialSanjay Noronha
7,296 PointsPython Slices reverse_evens problem : Not able to proceed
Hi Guys, Am stuck on this problem for a few days now. I believe my answer is correct but the system does not think so. Could you please let me know if my code is incorrect else let me move ahead. I am feeling pretty stuck here.
Cheers.
def first_4(inputValue):
return inputValue[:4]
def first_and_last_4(inputValue):
return inputValue[:4] + inputValue[-4:]
def odds(inputValue):
return inputValue[1::2]
def reverse_evens(inputValue):
return inputValue[::-2]
2 Answers
Thomas Fildes
22,687 PointsHi Sanjay,
The way I solved this challenge was to use the following code below:
inputValue[::2][::-1]
The code above allows you to take the even numbers first and then reverse it afterwards
Hope this helps! Happy Coding!!!
reanimator313
6,005 Pointsyour code return even index only when last index of the iterable is even. But if the last index is odd? Try an if statement or just play whit slice/slice
Sanjay Noronha
7,296 PointsThank you very much. I certainly did not grasp the requirement in total. Go well.
Sanjay Noronha
7,296 PointsSanjay Noronha
7,296 PointsThank you Thomas. This was very helpful. I did not grasp the requirement but I now do.