以下字符串,如果单词以辅音字母开头,则把辅音字母挪到最后,并在末尾加上“ay”。 如果以元音字母开头,则在末尾加上“hay”。 元音字母是“a.e.i.o.u” 字符串是“My name is Sho...

author:多测师_王sir

def func(str):
    '''
    :param str: 传入一个字符串"My name is Shopline,and i am 2,0000 days old"
    :return:
    '''
    result = []
    s = str.split()   #先进行分割为列表
    for word in s:
        if word[0] in "aeiou":#第一个字母在‘aeiou'中末尾加入‘hay'
            temp1= word + "hay"
            result.append(temp1)  #['ishay', 'ihay', 'amhay', 'oldhay']
        elif word[0] not in "aeiou": #第一个字母不是‘aeiou’,连续的辅音字母一起移动到单词末尾加入“ay”
            temp =""
            index = 0
            temp += word[0]
            for i in range(1,len(word)):
                if word[i] not in "aeiouy":
                    temp += word[i]   #把首个字母不在"aeiou"里面字符串进行拼接
                    index += 1
                else:
                    break
            #如果判断每个列表中的元素首个字母不在"aeiou"里面、index索引位置需要加上1、然后把temp挪到后面再加上ay字符串
            result.append(word[index+1:] + temp + "ay")
    print(result)

func("My name is Shopline,and i am 2,0000 days old")
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值