Skip to content

Instantly share code, notes, and snippets.

@agustinscigliano
Created April 4, 2018 13:47
Show Gist options
  • Save agustinscigliano/3291c8268f8c995cee0fbb5be643d088 to your computer and use it in GitHub Desktop.
Save agustinscigliano/3291c8268f8c995cee0fbb5be643d088 to your computer and use it in GitHub Desktop.
Combinations of keywords in matrix
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