Python单词尾缀的分析判断和提取

Python如何编写下列程序
给定单词为needed、raining、jumping、jumped、started,stars,请用if条件语句判断下列单词是ed结尾单词,或ing结尾单词,或其他类型。最终把三种类型的单词,分开打印(如下格式)。
ed结尾单词:
needed
jumped
started
ing结尾的单词;
rainig
jumping
其他类型的单词:
stars

题主要的代码如下

img

lst1='needed、raining、jumping、jumped、started、stars'.split('、')
lsted=[]
lsting=[]
lstother=[]
for word in lst1:
    if word.endswith('ed'):
        lsted.append(word)
    elif word.endswith('ing'):
        lsting.append(word)
    else:
        lstother.append(word)
print('ed结尾单词:')
print('\n'.join(lsted))
print('ing结尾单词:')
print('\n'.join(lsting))
print('其他类型的单词:')
print('\n'.join(lstother))

img

您好,我是有问必答小助手,您的问题已经有小伙伴帮您解答,感谢您对有问必答的支持与关注!
PS:问答VIP年卡 【限时加赠:IT技术图书免费领】,了解详情>>> https://vip.csdn.net/askvip?utm_source=1146287632