I have a list like this ['land_transport', 'and', 'or', 'port', 'of', 'surveyor', 'and', 'organization']
. I want to remove all of the words: and
, or
, of
. I, therefore, come up with the following block of code
my_list = ['land_transport', 'and', 'or', 'port', 'of', 'surveyor', 'and', 'organization']
print('Before: {}'.format(my_list))
my_list = list(filter(lambda a: 'and' not in a and 'of' not in a and 'or' not in a, my_list))
print('After: {}'.format(my_list))
However, my code gives the output like this
Before: ['land_transport', 'and', 'or', 'port', 'of', 'surveyor', 'and', 'organization']
After: []
What I want should be
['land_transport', 'port', 'surveyor', 'organization']
There are, of course, several ways to go around. But I want to insist on using lambda function to solve this problem. Any suggestions for my problem?