通俗地讲,就是返回可迭代对象的所有数学全排列方式。
from itertools import permutations
for item in permutations(['a', 'b', 'c']):
print(item)
('a', 'b', 'c')
('a', 'c', 'b')
('b', 'a', 'c')
('b', 'c', 'a')
('c', 'a', 'b')
('c', 'b', 'a')
Process finished with exit code 0
from itertools import permutations
for i in permutations('123', 2):
print(i)
('1', '2')
('1', '3')
('2', '1')
('2', '3')
('3', '1')
('3', '2')
Process finished with exit code 0