7. Reverse - How to remove spaces?


#1




So my code "returns 'none'", however the right-hand screen returns "! n o h t y PNone" which looks pretty good except I can't seem to kick the spaces. Any suggestions for how to get rid of the spaces and "none" line? As you can see I tried the ''.join maneuver with no luck.

Thanks in advance!


def reverse(text):
    almighty_text = []
    for i in text:
        almighty_text.append(i)
        
    backwards_count = -1
    for i in almighty_text: 
        reverse_text = almighty_text[backwards_count]
        backwards_count = backwards_count -1            
        print''.join(reverse_text),   
reverse("Python!")


#2

There might be spaces in the original so removing spaces is a bad idea because you would also be removing the ones that should be there. Do you really need to add them in the first place?

Also, is there a difference between printing and returning? Which one are you doing? Which one should you be doing?


#3

The instructions say to return, but using print allows me to see what is actually going on. I will change it once I get the program to work.

This is what is printed. "! n o h t y PNone". I need to remove those spaces, and that silly "none", any idea how to?


#4

Again, don't remove what should never be there in the first place.

If it says return, then do that instead. Build your string and return it. If you wish to print it, then call the function and print the result:

print reverse("Python!")

#5

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