I have a string, A = "abcdef", and several chars "a", "f" and "m". I want a condition to make sure none of the chars appears in A, i.e.,
if a not in A and f not in A and m not in A:
# do something
Is there a better way to do this? Thanks!
Sets are useful for this — see the
isdisjoint()method:edit after comment
sets are still you friend. If I’m following you better now, you want this (or something close to it):
We’ll just set everything up as sets to begin with for clarity:
If all of the chars in your set of characters is in the string, this happens:
If any of those characters are not present in your string, this happens:
Closer to what you need?