curriculum/challenges/english/blocks/daily-coding-challenges-python/68d2ba1468508398389487ce.md
Given a sentence, return a version of it that sounds like advice from a wise teacher using the following rules:
"have", "must", "are", "will", "can".For example, given "You must speak wisely." return "Speak wisely, you must."
wise_speak("You must speak wisely.") should return "Speak wisely, you must."
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(wise_speak("You must speak wisely."), "Speak wisely, you must.")`)
}})
wise_speak("You can do it!") should return "Do it, you can!"
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(wise_speak("You can do it!"), "Do it, you can!")`)
}})
wise_speak("Do you think you will complete this?") should return "Complete this, do you think you will?"
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(wise_speak("Do you think you will complete this?"), "Complete this, do you think you will?")`)
}})
wise_speak("All your base are belong to us.") should return "Belong to us, all your base are."
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(wise_speak("All your base are belong to us."), "Belong to us, all your base are.")`)
}})
wise_speak("You have much to learn.") should return "Much to learn, you have."
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(wise_speak("You have much to learn."), "Much to learn, you have.")`)
}})
def wise_speak(sentence):
return sentence
def wise_speak(sentence):
triggers = ["have", "must", "are", "will", "can"]
punctuation = sentence[-1]
words = sentence[:-1].split(" ")
index = next(i for i, w in enumerate(words) if w in triggers)
to_move = [w.lower() for w in words[:index + 1]]
remaining = words[index + 1:]
if remaining:
remaining[0] = remaining[0][0].upper() + remaining[0][1:]
return " ".join(remaining) + ", " + " ".join(to_move) + punctuation