Convert both strings to sets and check if they are equal. If yes, your string contains a
AND b
AND c
:
valid = set(your_string) == set('abc')...
Use issubset
to check if it contains ANY of a, b, c:
valid = set(your_string) <= set('abc')
or
valid = set(your_string).issubset('abc')
Subtract the sets to find out invalid characters:
bad_chars = set('abcXYcba') - set('abc') # set(X,Y)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…