If a password must consist of ASCII letters and numbers only, then the most efficient approach would be to use sets:
from string import ascii_lowercase, ascii_uppercase, digits
def is_valid(password):
if len(password) < 7:
return False
password_set = set(password)
return not any(password_set.isdisjoint(x)
for x in (ascii_lowercase, ascii_uppercase, digits))
If unicode characters are allowed, you could use any():
def is_valid(password):
return (len(password) >= 7 and
any(c.islower() for c in password) and
any(c.isupper() for c in password) and
any(c.isdigit() for c in password))