开发者

Try all the combinations (cases) Function

I've been struggling with the cutting stock problem for a while, and I need to do a funcion that given an array of values, gives me an array of array for all the possible开发者_如何学JAVA combinations.

I trying to do this function, but (as everything in python), I think someone must have done it better :).

I think the name of the function is combination. Does anyone know whats the best way to do this, and what's the best module and function for this

P.s. I have read some papers on the matter, but the matematical terms dazzle me :)


>>> from itertools import permutations
>>> x = range(3)
>>> list(permutations(x))
[(0, 1, 2), (0, 2, 1), (1, 0, 2), (1, 2, 0), (2, 0, 1), (2, 1, 0)]
>>> 


Do you mean itertools.combinations?


>>> from itertools import combinations
>>> list(combinations('abcd', 2))
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜