2019-04-16:倒序取出每个单词的第一个字母

#encoding=utf-8
"""
倒序取出每个单词的第一个字母
"""
#方法一 倒序取出每一个单纯,然后取出对应单词的第一个字母
def flash_Back_Letters(s):
    re_s=s.split(" ")
    target_Str=""
    for i in range(len(re_s)-1,-1,-1):#倒序的开始一定要减掉1,不然会报 list index out of range
        #print(re_s[i])
        if re_s[i]==".":
            continue
        else:
            target_Str+=re_s[i][0]
    return target_Str
#print(flash_Back_Letters("if you can think it . you can do it"))



#方法二 取出每个单词的首字母,再把所有的字母翻转
def flash_Back_Letters1(s):
    re_s = s.split(" ")
    target_List = []
    for i in range(len(re_s)):  # 倒序的开始一定要减掉1,不然会报 list index out of range
        if re_s[i] == ".":
            continue
        else:
            target_List.append(re_s[i][0])
    target_List.reverse()
    return "".join(target_List)


print(flash_Back_Letters("if you can think it . you can do it"))
print(flash_Back_Letters1("if you can think it . you can do it"))


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值