1 2 3 4 5 6 7 8
def gen(chars, deep): if deep == 0: return for ch in chars: yield ch for chs in gen(chars, deep-1): yield ch+chs