Created
July 6, 2019 14:57
-
-
Save Cyborg-Model-Z/216ef375b94e6a100e621253202db6cf to your computer and use it in GitHub Desktop.
Reverse a sentence
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| text = "python is fun" | |
| substring = " " | |
| def spaces(text): | |
| return (str[::text.count(" ", 0,100)]) | |
| spaces(text) | |
| print (spaces("to sit in solemn silence")) |
Author
def reverse_words(text):
""" Reverses a string of words by:
1. Splitting the string into the individual words
2. Reversing the list of words
3. Joining the words into a string again
"""
return " ".join(reversed(text.split(" ")))
So you could have:
def join_spaced(items):
pass
def my_reversed(items):
pass
def split_words(text):
pass
def reverse_words(text):
return join_spaced(my_reversed(split_words(text)))
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
def reverseWords(text):
backwardsentence = ""
for i in text.split(" ")[-1::-1]:
backwardsentence += str(i) + " "
return (backwardntence)[:-1]
reverseWords("to sit in solemn silence")
@Camsbury