开发者

Adding extra state to itertools.product

开发者 https://www.devze.com 2023-04-10 04:30 出处:网络
I have taken a look at itertools.permutations and combinations, but I don\'t think they will work for my issue.

I have taken a look at itertools.permutations and combinations, but I don't think they will work for my issue.

开发者_如何学Go

Basically, 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消