Last active
August 29, 2015 13:56
-
-
Save balkian/9186599 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a=set([1,2,3,4]) | |
b=set([4,5,6,7]) | |
c=set([7,8,9]) | |
def array_combinations(*args): | |
combinations = [[i] for i in set(args[0])] | |
for arg in args[1:]: | |
tempcomb = [] | |
for i in set(arg): | |
tempcomb += [c+[i] for c in combinations if i not in c ] | |
combinations = tempcomb | |
return combinations | |
res = array_combinations(a,b,c) | |
print res | |
print len(res) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def array_combinations(*args): | |
combinations = set([frozenset([i]) for i in set(args[0])]) | |
for arg in args[1:]: | |
tempcomb = [] | |
for i in set(arg): | |
tempcomb += [frozenset(list(c)+[i]) for c in combinations if i not in c ] | |
combinations = set(tempcomb) | |
return [list(comb) for comb in combinations] | |
res = array_combinations(a,b) | |
print res | |
print len(res) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment