返回可迭代对象的所有全排列方式
import itertools
sum2 = 0
a = [1,2,3]
for i in itertools.permutations(a, 2):
print("%d%d"%(i[0],i[1]))
sum2 += 1
print(sum2)
12
13
21
23
31
32
6
sum2 = 0
for i in itertools.permutations(['a', 'b', 'c']):
print(i)
sum2 += 1
print(sum2)
('a', 'b', 'c')
('a', 'c', 'b')
('b', 'a', 'c')
('b', 'c', 'a')
('c', 'a', 'b')
('c', 'b', 'a')
6