xpermutations.py (824B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\carbon\common\script\util\xpermutations.py 2 3 4 def xcombinations(items, n): 5 if n == 0: 6 yield [] 7 else: 8 for i in xrange(len(items)): 9 for cc in xcombinations(items[:i] + items[i + 1:], n - 1): 10 yield [items[i]] + cc 11 12 13 def xuniqueCombinations(items, n): 14 if n == 0: 15 yield [] 16 else: 17 for i in xrange(len(items)): 18 for cc in xuniqueCombinations(items[i + 1:], n - 1): 19 yield [items[i]] + cc 20 21 22 def xselections(items, n): 23 if n == 0: 24 yield [] 25 else: 26 for i in xrange(len(items)): 27 for ss in xselections(items, n - 1): 28 yield [items[i]] + ss 29 30 31 def xpermutations(items): 32 return xcombinations(items, len(items))