Created
April 14, 2016 10:12
-
-
Save dionisos2/805f5702a5f552852392bd4b0533011b to your computer and use it in GitHub Desktop.
This file contains 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
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