您可以使用itertools.permutations和itertools.chain.from_iterable:from itertools import chain, permutationsrack = 'QOFTHEA'lo, hi = 2, 7for perm in chain.from_iterable(permutations(rack, i) for i in range(lo, hi + 1)): print(perm)如果你想要一个字符串而不是一个字符元组,你可以做''.join(perm).