7/15 Now I'm confused...I think there's an error


#1

I wrote this code and I runned it in my Idle, and worked just fine. if I change the 'return' for a print and call the function 'reverse' works perfectly.

But, when I run in the Codecademy' idle tells me that the function returns "cba!nohtyP". This just not make any sense where come from the "abc" :confused:

lista={}
nue = []
def reverse (text):
for i,j in enumerate(text):
        lista[i]=j
    l= sorted(lista,reverse = True)
    for n in l:
        nue.append(lista[n])
    return "".join(nue)
    print nue

The error that shows me is:

:warning:Oops, try again. Your function fails on reverse("Python!"). It returns "cba!nohtyP" when it should return "!nohtyP".


#2

Your function shouldn't store its data outside itself.
Each time you call your function you are currently adding to that dict/list and they'll keep growing every time.
Your function should create an empty list, populate it and once it's done that list should be forgotten about because it's no longer needed.