Skip to content

Instantly share code, notes, and snippets.

@Quidge
Created April 22, 2018 20:48
Show Gist options
  • Save Quidge/61cae097fac24f0cd39784fcf63050b4 to your computer and use it in GitHub Desktop.
Save Quidge/61cae097fac24f0cd39784fcf63050b4 to your computer and use it in GitHub Desktop.
def spin_words(sentence):
flipped_list = []
str_list = sentence.split(" ")
for word in str_list:
if len(word) < 5:
flipped_list.append(word)
else:
flipped_word = ""
for i in range(len(word), 0, -1):
flipped_word = flipped_word + word[i-1]
flipped_list.append(flipped_word)
return " ".join(flipped_list)
def spin_words2(sentence):
str_list = sentence.split(" ")
def flip_word(word):
flipped = "".join([word[i - 1] for i in range(len(word), 0, -1)])
return flipped
flip_list = " ".join([flip_word(wrd) if len(wrd) > 4 else wrd for wrd in str_list])
return flip_list
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment