Search code examples
pythonreversesentence

How do I reverse a sentence in python?


I've been searching for a way to reverse sentences, but I can't seem to find one. I was hoping to find a way in Python; however, I'm not sure if there is a way to do it. If anybody knows of a way to do it, I would really appreciate the help.


Solution

  • This would reverse "the quick brown fox" to "xof nworb kciuq eht". Is that what you mean?

    str1 = "the quick brown fox"
    str2 = ""
    
    for i in range(len(str1)):
        str2 += str1[(len(str1)-i)-1]
    
    print(str2)