Suppose I have the list L of size n >= k in Python. I wish to generate all multisets of size k of the elements of L. Here, by a multiset I mean a subset of L which is allowed to have repeated elements from L. Thanks!
Asked
Active
Viewed 372 times
2
-
3Not quite sure what you want, but maybe [`itertools.combinations_with_replacement`](https://docs.python.org/2/library/itertools.html#itertools.combinations_with_replacement)? – NightShadeQueen Aug 07 '15 at 19:23
-
1possible duplicate of [Generate all subsets of size k (containing k elements) in Python](http://stackoverflow.com/questions/7378180/generate-all-subsets-of-size-k-containing-k-elements-in-python) – Chaker Aug 07 '15 at 19:27
-
Yes, itertools.combinations_with_replacement does what I want. Thank you! – Mitchell Eithun Aug 07 '15 at 19:29