From 9cfc2da26524287f6166cc20ca88ad568f762143 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=2E=20Fernando=20S=C3=A1nchez?= Date: Tue, 25 Feb 2014 08:00:51 -0800 Subject: [PATCH] --- frozen_combination.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 frozen_combination.py diff --git a/frozen_combination.py b/frozen_combination.py new file mode 100644 index 0000000..d8e193f --- /dev/null +++ b/frozen_combination.py @@ -0,0 +1,13 @@ +def frozen_combination(*args): + combinations = set([frozenset(),]) + for arg in args: + tempcomb = set(frozenset(),) + for i in set(arg): + tempcomb.update(set([frozenset(list(c)+[i]) for c in combinations if i not in c])) + if len(tempcomb) > 0: + combinations = tempcomb + return combinations +# return [set(comb) for comb in combinations] # for sets instead of frozensets +res = frozen_combination(a,b) +print res +print len(res) \ No newline at end of file