【python 排列组合】Python实现排列组合

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u013421629/article/details/82498643

调用 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

猜你喜欢

转载自blog.csdn.net/u013421629/article/details/82498643