编写一个python函数,以便
奇数词位置:反转在
偶数词位置:重新排列使所有辅音 出现在元音之前,其顺序不应改变
在输入:太阳在东方崛起 输出:eht snusesir ni eht stea公司
我已将字符串反转,但无法重新排列字符。 我们可以使用append和join函数还是需要在末尾进行交换。 基本上,弦的旋转已经完成了,我们怎样才能达到这个目的。在
def encrypt_sentence(sentence):
vowel_set = set("aeiouAEIOU")
final_list=[]
word=sentence.split()
for i in range(0,len(word)):
if((i%2)==0):
final_list.append(word[i][::-1])
else:
final_list.append("".join(c for c in word if c not in vowel_set))
print(final_list)
encrypt_sentence("the sun rises in the east")
我会反复检查字母以跟踪元音和辅音,然后在末尾使用join。在
尝试使用两种列表理解法:
相关问题 更多 >
编程相关推荐