Reverse


#1



So I'm stuck at the reverse section. It's sort of working, but not perfectly.

When I put 'reverse('Python!')' on line 4 to see how it behaves in the console, it prints out '! n o h t y P'. There used to be a return after every character until I put the comma at the end of line 3.

I need to know how to get rid of those spaces and make it not return 'none.' I've seen some other people use counters to do this specific section, but I'd like to see this done without the use of counters.


def reverse(text):
    for char in text:
        print text[(len(text)-text.index(char))-1],


#2

Well @alex.kampas,

You cannot get rid of those spaces because that is the way Python 2.7.11's print statement behaves. Your function is returning None because you haven't told it to return anything using the return statement. Your way is effective, however I would personally suggest appending characters to an array instead of printing them, and that array can then be returned. Hope this clears out your doubts.


#3

I also just tried putting longer strings and sentences in the sample part of line 4.. If there aren't any spaces, it's fine. When I put more words (and thus more spaces) it begins returning/printing nonsense. I think it has to do with the 'char' in the for statement looking at the actual characters and not the spaces, where the index numbers take into account the spaces. These are all assumptions based on observations, though. I may be completely wrong.