1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| import itertools
''' 无序排列 combinations(M个数的集合,选取N个数为一组) ''' c = list(itertools.combinations([1, 2, 3, 4], 2)) print(c)
''' 有序排列 permutations(M个数的集合,选取N个数为一组) ''' p = list(itertools.permutations([1, 2, 3, 4], 2)) print(p)
''' 测试结果: [(1, 2), (1, 3), (1, 4), (2, 3), (2, 4), (3, 4)] [(1, 2), (1, 3), (1, 4), (2, 1), (2, 3), (2, 4), (3, 1), (3, 2), (3, 4), (4, 1), (4, 2), (4, 3)] '''
|