Reverse. How can i get a better output?


#1




I have done this with a list and using the join function it works and that is ok but there is a way to remove the spaces between characters?
Or can i do this using a different method too?


def reverse (text):
    bottomup = []
    c=len(text)
    while c>0:
        c-=1
        print text[c],
        bottomup.append(text[c])
    return "".join(bottomup)

    
text = raw_input("Inserire parola da tradurre in reverse:")
reverse (text)
print''


#2

what is currently shown in the output is cause by this print:

print text[c],

if you want to see the reversed string, i would simply recommend to print what the function returns, you do this by adding a print statement to the function call:

print reverse (text)

#3

Oh thanks! Now is totally better xD


#4

yes, .join() made sure the string was perfectly joined, you just needed to print it :wink:


#5

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.