I have a suggestion, say:
Fast brown fox jumps over a lazy dog
I want to create a function that takes 2 arguments, a sentence and a list of things to ignore. And he returns this sentence with the opposite words, however, he should ignore the material that I pass to him in the second argument. This is what I have at the moment:
def main(sentence, ignores):
return ' '.join(word[::-1] if word not in ignores else word for word in sentence.split())
But this will only work if I pass the second list:
print(main('The quick brown fox jumps over the lazy dog', ['quick', 'lazy']))
However, I want to pass the list as follows:
print(main('The quick brown fox jumps over the lazy dog', ['quick brown', 'lazy dog']))
Expected Result:
ehT quick brown xof spmuj revo eht lazy dog
Thus, basically the second argument (list) will contain parts of the sentence that should be ignored. Not just single words.
Should I use regexp for this? I tried to avoid this ...