-
-def xselections(items, n):
- """Iterate through all length `n` multisets of `items`.
-
- >>> for c in xselections([1, 2, 3], 2):
- ... print c
- [1, 1]
- [1, 2]
- [1, 3]
- [2, 1]
- [2, 2]
- [2, 3]
- [3, 1]
- [3, 2]
- [3, 3]
- """
- if n==0: yield []
- else:
- for i in xrange(len(items)):
- for ss in xselections(items, n-1):
- yield [items[i]]+ss
-
-def xpermutations(items):
- """Iterate through all permutations of `items`.
-
- >>> for c in xpermutations([1, 2, 3]):
- ... print c
- [1, 2, 3]
- [1, 3, 2]
- [2, 1, 3]
- [2, 3, 1]
- [3, 1, 2]
- [3, 2, 1]
- """
- return xcombinations(items, len(items))
-