python中编程技巧,要巧妙运用字符串类型
- 输入的数字创建数字字符串列表
- 全排列利用递归来做,每次去掉一个,对其他的做全排列然后在在前面加上去掉的那个数字字符
def perm(num):
rs = []
if len(num) <= 1:
rs.append(num)
return rs
else:
for i in range(len(num)):
newnum = num[:i]+num[i+1:]
newrs = perm(newnum)
for s in newrs:
s1 = num[i] + s
rs.append(s1)
return rs
n = int(input())
ns = ''.join([str(i) for i in range(1,n+1)])
for k in perm(ns):
print(k)