请问全排列要怎么排列
s1 = 'ABC'
s2 = '123'
s3 = 'xyz'
result = ''
for a in s1:
for b in s2:
for c in s3:
print(a+b+c)
之后要怎么继续排列,才能得到全排列?
如果继续print(a+c+b)把六种方式都列出来感觉有点赘余,假如要列的不止三个字符长度而是n个,要怎么写简便的代码?
s1 = 'ABC'
s2 = '123'
s3 = 'xyz'
result = ''
for a in s1:
for b in s2:
for c in s3:
print(a+b+c)
之后要怎么继续排列,才能得到全排列?
如果继续print(a+c+b)把六种方式都列出来感觉有点赘余,假如要列的不止三个字符长度而是n个,要怎么写简便的代码?
2021-04-04
举报