python - Writing an If condition to filter out the first word -
i have string:
father ate banana , slept on feather
part of code shown below:
... if word.endswith(('ther')): print word
this prints feather
, father
but want modify if condition
doesn't apply search first word of sentence. result should print feather
.
i tried having and
didn't work:
... if word.endswith(('ther')) , word[0].endswith(('ther')): print word
this doesn't work. help
you can use range skip first word , apply endswith()
function rest of words, like:
s = 'father ate banana , slept on feather' [w w in s.split()[1:] if w.endswith('ther')]
Comments
Post a Comment