Adding extra state to itertools.product
I have taken a look at itertools.permutations and combinations, but I don't think they will work for my issue.
开发者_如何学GoBasically, I am looking to create a list of all possible permutations of a given string with a defined length (greater than the amount of elements).
Basically, I would like to have three possible states, 0, 1, or don't care [0,1,'*'].
I had hoped to do something like:
s = list(itertools.product(('0','1','*'), repeat=8))
However, product doesn't seem to like more than 2 parameters in its first parameter.
If I try to scale up the permutations or combinations (ie greater than the amount of combinations) I end up with an empty array returned.
Works for me:
>>> import itertools
>>> s = list(itertools.product(('0','1','*'), repeat=8))
>>> len(s)
6561
See it working online: ideone.
精彩评论