botechga

Permutations

Sep 21st, 2020
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.57 KB | None | 0 0
  1. import itertools
  2. import time
  3.  
  4. start = time.time()
  5.  
  6. locs = ['A Obj1', 'A Obj2',
  7.         'B Obj1', 'B Obj2',
  8.         'C Obj1', 'C Obj2',
  9.         'D Obj1', 'D Obj2']
  10.  
  11. p = itertools.combinations(locs,2)
  12. n = 0
  13. for p in p:
  14.     if not (locs[0] in p and locs[1] in p):
  15.         if not (locs[2] in p and locs[3] in p):
  16.             if not (locs[4] in p and locs[5] in p):
  17.                 if not (locs[6] in p and locs[7] in p):
  18.                     n += 1
  19.                     print(p)
  20.  
  21. fin = time.time() - start
  22.  
  23. print('%i total combinations found in %.4f seconds' %(n, fin))
Advertisement
Add Comment
Please, Sign In to add comment