Created
January 4, 2020 16:56
-
-
Save kkt-ee/97107458b06bc033c41870ec56be3539 to your computer and use it in GitHub Desktop.
This file contains 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
#'sroirraw wollef Hey' should equal 'Hey wollef sroirraw' | |
def spin_words(sentence): | |
# Your code goes here | |
words = sentence.split(' ')[::-1] | |
newL = list() | |
for word in words: | |
newL.append(word) if len(word)<5 else newL.append(word[::-1]) | |
return ' '.join(newL) | |
spin_words("sroirraw wollef Hey") | |
#OR | |
def spin_words(sentence): | |
# Your code goes here | |
return " ".join([x[::-1] if len(x) >= 5 else x for x in sentence.split(" ")]) | |
#OR | |
def spin_words(sentence): | |
words = [word for word in sentence.split(" ")] | |
words = [word if len(word) < 5 else word[::-1] for word in words] | |
return " ".join(words) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment