def valid(p: str) -> bool: if {'i', 'o', 'l'}.intersection(set(p)): return False def next_password(p: str) -> str: if p[-1] == 'z': return next_password(p[:-1]) + 'a' else: return p[:-1] + chr(ord(p[-1]) + 1) pw = next_password('cqjxjnds') while not valid(pw): pw = next_password(pw) print(pw) pw = next_password(pw) while not valid(pw): pw = next_password(pw) print(pw)