写入If条件以过滤掉第一个单词

use*_*906 0 python string search

我有一个字符串:

父亲吃了一根香蕉,睡在羽毛上

我的部分代码如下所示:

...

if word.endswith(('ther')):
   print word
Run Code Online (Sandbox Code Playgroud)

这打印featherFather

但我想修改它,if condition因此它不会将此搜索应用于句子的第一个单词.所以结果应该只打印feather.

我试过and但它没有用:

...

if word.endswith(('ther')) and word[0].endswith(('ther')):
   print word
Run Code Online (Sandbox Code Playgroud)

这不起作用.救命

Bir*_*rei 6

您可以使用范围跳过第一个单词并将该endswith()函数应用于其余单词,例如:

s = 'Father ate a banana and slept on a feather'
[w for w in s.split()[1:] if w.endswith('ther')]
Run Code Online (Sandbox Code Playgroud)