Here is my list:
pos = [['det'], ['noun', 'adj'], ['noun'], ['vb'], ['det'], ['vb', 'noun', 'adj']]
Or
pos = ['det', ['noun', 'adj'], 'noun', 'vb', 'det', ['vb', 'noun', 'adj']]
I'm trying to print all the combinations:
det noun noun vb det vb
det adj noun vb det vb
det noun noun vb det noun
det adj noun vb det noun
det noun noun vb det adj
det adj noun vb det adj
Should I use recursive function? I tried with no result.
Itertools (permutations, product, combinations) doesn't help me.
Could you help me?
解决方案
I think itertools.product() actually is what you are looking for:
pos = [['det'], ['noun', 'adj'], ['noun'],
['vb'], ['det'], ['vb', 'noun', 'adj']]
for x in itertools.product(*pos):
print " ".join(x)
prints
det noun noun vb det vb
det noun noun vb det noun
det noun noun vb det adj
det adj noun vb det vb
det adj noun vb det noun
det adj noun vb det adj