Generate all permutations with sort constraint

Posted by Moos Hueting on Stack Overflow See other posts from Stack Overflow or by Moos Hueting
Published on 2010-05-31T15:47:26Z Indexed on 2010/05/31 16:12 UTC
Read the original article Hit count: 199

Filed under:

Hi!

I have a list consisting of other lists and some zeroes, for example:

x = [[1, 1, 2], [1, 1, 1, 2], [1, 1, 2], 0, 0, 0]

I would like to generate all the combinations of this list while keeping the order of the inner lists unchanged, so

[[1, 1, 2], 0, 0, [1, 1, 1, 2], [1, 1, 2], 0]

is fine, but

[[1, 1, 1, 2], [1, 1, 2], 0, 0, [1, 1, 2], 0]

isn't. I've got the feeling that this should be fairly easy in Python, but I just don't see it. Could somebody help me out?

© Stack Overflow or respective owner

Related posts about python