Edited
After you were provided with a wealth of solutions, here's a my favorite - use the fact that the boolean equivalent of an empty set is
After you were provided with a wealth of solutions, here's a my favorite - use the fact that the boolean equivalent of an empty set is
False
def avoids(word, forbidden): return not set(forbidden).intersection(word.lower())PS The name of function does not match the result - it returns
True
when a word is allowed and False
when a word should be avoided, that has confused me. allowed_word
would have been better name
Test everything in a Python shell (iPython, Azure Notebook, etc.)
- Someone gave you an advice you liked? Test it - maybe the advice was actually bad.
- Someone gave you an advice you think is bad? Test it before arguing - maybe it was good.
- You posted a claim that something you did not test works? Be prepared to eat your hat.