我想创建一个遍历字符串的循环,如果字母“r”跟随元音,它将删除元音。例如:
Enter word: Cracker
New word: Crackr
或者
Enter word: Flirk
New word: Flrk
我已经有办法做到这一点,但它不是很整洁。我只是想知道如何提高自己。我这样做的方式是:
if "ar" in s or "er" in s or "ir" in s or "or" in s or "ur" in s:
s = s.replace("ar","r")
s = s.replace("er","r")
s = s.replace("ir","r")
s = s.replace("or","r")
s = s.replace("ur","r")
谢谢