有谁能帮我用python代码把单词/字符串转换成如下形式,把所有辅音移到元音之前-辅音和元音的顺序应该和原来的相反。-如果结果中两个相等的字母相邻(不区分大小写的副本),请在源代码中删除第二个字母。你知道吗
我试过这个:
def vowels(x):
vowel = ["a", "e", "i", "o", "u", "A", "E", "I", "O", "U"]
if x in vowel:
return True
else:
return False
def transform_word(word):
result = ""
if word is not None:
x = len(word) - 1
v = ""
c = ""
while x is not -1:
if (vowels(word[x])):
v += word[x]
x -= 1
else:
c += word[x]
x-=1
result = c + v
result = "".join(OrderedDict.fromkeys(result))
return result
应该工作,或多或少你有什么概念明智的,更糟糕的字符串连接。你知道吗
相关问题 更多 >
编程相关推荐