37,718
社区成员
发帖
与我相关
我的任务
分享
L=['A','B','C']
def func(prt_str,deepth): #deepth是传入的是深度
if deepth>1:
for item in L:
func(prt_str+item,deepth-1)
else:
for item in L:
print(prt_str+item)
func("",3)
如果要打印从第一层到第11层的结果,自己在外面写个for循环调用func即可。
# -*- coding: UTF-8 -*-
from itertools import product
L = ['A','B','C','D','E','F','G','H','I','J','K']
n = 3
for i in range(1, n+1):
print(list(map(''.join, product(L, repeat=i))))
n最好不要写成11,因为你根本不明白那意味着什么。