def assignments(n, m, used=0):
    """Generate assignments of `n` items to `m` indistinguishable
    buckets, where `used` buckets have been used so far.
        >>> list(assignments(3, 1))
        [(0, 0, 0)]
        >>> list(assignments(3, 2))
        [(0, 0, 0), (0, 0, 1), (0, 1, 0), (0, 1, 1)]
        >>> list(assignments(3, 3))
        [(0, 0, 0), (0, 0, 1), (0, 1, 0), (0, 1, 1), (0, 1, 2)]
    """
if n == 0:
    yield ()
return
aa = list(assignments(n - 1, m, used))
for first in range(used):
    for a in aa:
        yield (first,) + a
if used < m:
    for a in assignments(n - 1, m, used + 1):
        yield (used,) + a
Generating a list of repetitions regardless of the order