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 trialOszkár Fehér
Treehouse Project ReviewerI am confused, maybe i didn't understood the question well
Please somebody can explain to me why this code is not accepted?
import random
backwards = [
'tac',
'esuoheerT',
'htenneK',
[5, 4, 3, 2, 1],
]
def reverse(args):
item = random.choice(args)
item = item[::-1]
return item
3 Answers
Jon Mirow
9,864 PointsI'm not a pro member, so can't attempt the question but I think your function does too much. The question asks for a function that takes an iterable and returns the iterable in the reverse order. You got the method for reversing correct, but I suspect your function is trying to do something other than what is asked. It doesn't ask for you to return an iterable in reverse order chosen at random from a list of iterables, it just asks for a function that takes one iterable and reverses it.
I think the confusion may have come from the backwards list? I'm pretty sure that's just for testing your function. For example:
backwards = [
'tac',
'esuoheerT',
'htenneK',
[5, 4, 3, 2, 1],
]
def reverse(arr):
"""
your code
"""
for x in backwards:
print(reverse(x))
To see if your reverse function works (hint your function need only be a single return line)
Oszkár Fehér
Treehouse Project ReviewerCreate a function named reversethat takes a single iterable item and returns a reversed version of that item.
Oszkár Fehér
Treehouse Project ReviewerThis is what the quiz ask, a single iterable item and it's not specified witch item that's why I choose randomly. I could reverse the list to very easily but the question it doesn't specify this.
Oszkár Fehér
Treehouse Project Revieweri passed the test by reversing the list
return args[::-1]
Nate Hawk
13,229 PointsIt is asking you to reverse any given iterable and not a random one. I think that's where your confusion was. So the functions input should be an iterable, then it should take that iterable, reverse it and return the result. I got caught up on any iterable, so although there are not examples in the course to this point, you will need to handle strings differently.
Oszkár Fehér
Treehouse Project ReviewerOszkár Fehér
Treehouse Project Reviewerthis does the same: ---return random.choice(args)[::-1]---