Get all combinations of list elements not ignoring position in Python -
i want combine elements of list sublists (not tuples) specified length.
the itertools.combinations_with_replacement
generator want achieve:
>>> list(itertools.combinations_with_replacement([1,2],2)) [(1, 1), (1, 2), (2, 2)]
there 2 things dislike: creates tuples instead of sublists (what alter map), , misses element (2,1)
in illustration above.
is there builtin module in python 2 want? if not, there simple way @ to the lowest degree combinations_with_replacements
(or other module function) generate missing element in provided example?
maybe:
>>> itertools import product >>> list(product([1, 2], repeat=2)) [(1, 1), (1, 2), (2, 1), (2, 2)]
python python-2.7 python-2.x
No comments:
Post a Comment