# coding=utf-8 import random def generate_password(password_length): digits_and_ascii_letters = list('0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ') ignore_strings = list('lIO0') password_strings = [s for s in digits_and_ascii_letters if s not in ignore_strings] return ''.join(random.sample(password_strings, password_length)) print(generate_password(8)) # -> t73WXSEc