调用 itertools 获取排列组合的全部情况数
# -*- encoding=utf-8 -*-
from itertools import combinations,permutations
# 排列
test_data = {'1', '2', '3'}
print('排列有:')
for i,j in permutations(test_data, 2):
print(i,j)
# 组合
print('组合有:')
for i,j in combinations(test_data, 2):
print(i,j)
排列有:
3 1
3 2
1 3
1 2
2 3
2 1
组合有:
3 1
3 2
1 2
Process finished with exit code 0