You can check if SOMETHINGTOCOMPARE
is a subset of whitelist
(set):
def check(SOMETHINGTOCOMPARE):
whitelist = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','1','2','3','4','5','6','7','8','9','0']
# Test whether every element in SOMETHINGTOCOMPARE is in whitelist.
if set(SOMETHINGTOCOMPARE) <= set(whitelist):
return True
return False
You can test the function with:
if check('[email protected][email protected]'):
print("You are allowed to look this username up.")
else:
print("Your username contains special characters. Disallowed.")
if check('Anf'):
print("You are allowed to look this username up.")
else:
print("Your username contains special characters. Disallowed.")
if check('GGDFG94'):
print("You are allowed to look this username up.")
else:
print("Your username contains special characters. Disallowed.")
CLICK HERE to find out more related problems solutions.