Skip to content

Instantly share code, notes, and snippets.

@dionisos2
Created April 14, 2016 10:12
Show Gist options
  • Save dionisos2/805f5702a5f552852392bd4b0533011b to your computer and use it in GitHub Desktop.
Save dionisos2/805f5702a5f552852392bd4b0533011b to your computer and use it in GitHub Desktop.
class Combination:
def __init__(self, elements, len_list):
self.elements = elements
self.len_list = len_list
def __len__(self):
return pow(len(self.elements), self.len_list)
def __iter__(self):
for element in self.elements:
if (self.len_list > 1):
for sub_combination in Combination(self.elements, self.len_list - 1):
yield [element] + sub_combination
else:
yield [element]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment