I have a set of characters, for example: array = ['abc', 'adc, 'cf', 'xyy']
and I have a string: my_word = 'trycf'
I want to write a function that check if the last elements of my_word contain an element of my array. If this is the case, I want to remove it.
I already used endswith
such as:
if my_word.endswith('cf'): my_word.remove('cf')
Then it returns me the word try
.
I don't know how to use endswith
in the case that I have a list like my array
. I know that endswith can take array as parameter (such as if my_word.endswith(array):
) but in this case, I dont know how to take the index of 'cf'
from my array to remove it. Can you help me on this please?
I think what you need is a for loop (https://www.tutorialspoint.com/python/python_for_loop.htm):