Permutations and Combinations using Python

Permutations and Combinations using Python

https://www.askpython.com/python/permutations-and-combinations-using-python

 

# A Python program to print all
# combinations of given length
from itertools import combinations
 
# Get all combinations of [1, 2, 3]
# and length 2
'''
tmp = [[  2 -61 -58]
 [  0 -61 -64]
 [  1 -61 -67]
 [  3 -61 -79]
 [  7 -61 -83]
 [  6 -61 -83]
 [  5 -61 -90]
 [  4 -61 -96]]
'''

tmp =  [[0, -61, -64], [1, -61, -67], [2, -61, -58], [3, -61, -79], [4, -61, -96], [5, -61, -90], [6, -61, -83], [7, -61, -83]] 

comb = combinations(tmp, 2)
 
# Print the obtained combinations
# for i in comb:
for i in list(comb):
    print (i)

 

output:

([0, -61, -64], [1, -61, -67])
([0, -61, -64], [2, -61, -58])
([0, -61, -64], [3, -61, -79])
([0, -61, -64], [4, -61, -96])
([0, -61, -64], [5, -61, -90])
([0, -61, -64], [6, -61, -83])
([0, -61, -64], [7, -61, -83])
([1, -61, -67], [2, -61, -58])
([1, -61, -67], [3, -61, -79])
([1, -61, -67], [4, -61, -96])
([1, -61, -67], [5, -61, -90])
([1, -61, -67], [6, -61, -83])
([1, -61, -67], [7, -61, -83])
([2, -61, -58], [3, -61, -79])
([2, -61, -58], [4, -61, -96])
([2, -61, -58], [5, -61, -90])
([2, -61, -58], [6, -61, -83])
([2, -61, -58], [7, -61, -83])
([3, -61, -79], [4, -61, -96])
([3, -61, -79], [5, -61, -90])
([3, -61, -79], [6, -61, -83])
([3, -61, -79], [7, -61, -83])
([4, -61, -96], [5, -61, -90])
([4, -61, -96], [6, -61, -83])
([4, -61, -96], [7, -61, -83])
([5, -61, -90], [6, -61, -83])
([5, -61, -90], [7, -61, -83])
([6, -61, -83], [7, -61, -83])

 

posted @ 2021-11-22 11:49  dong1  阅读(31)  评论(0编辑  收藏  举报