Skip to content

Instantly share code, notes, and snippets.

@kkt-ee
Created January 4, 2020 16:56
Show Gist options
  • Save kkt-ee/97107458b06bc033c41870ec56be3539 to your computer and use it in GitHub Desktop.
Save kkt-ee/97107458b06bc033c41870ec56be3539 to your computer and use it in GitHub Desktop.
#'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