Created
April 4, 2018 13:47
-
-
Save agustinscigliano/3291c8268f8c995cee0fbb5be643d088 to your computer and use it in GitHub Desktop.
Combinations of keywords in matrix
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
def combinations(keywords, opts): | |
if len(keywords) == 0: | |
return [[]] | |
else: | |
res = [] | |
for opt in opts[keywords[0]]: | |
for combination in combinations(keywords[1:], opts): | |
res.append([opt] + combination) | |
return res | |
keywords = ['a', 'b'] | |
opts = { 'a': ['a1', 'a2'], 'b': ['b1', 'b2']} | |
for combination in combinations(keywords, opts): | |
print combination |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment