Mark Dickinson <dicki...@gmail.com> added the comment: And using combinations_with_replacement, it's even a one-liner:
>>> balls_in_boxes = lambda n, k: (tuple(map(c.count, range(k))) for c in >>> combinations_with_replacement(range(k), n)) >>> for item in balls_in_boxes(5,3): print(item) ... (5, 0, 0) (4, 1, 0) (4, 0, 1) (3, 2, 0) (3, 1, 1) (3, 0, 2) (2, 3, 0) (2, 2, 1) (2, 1, 2) (2, 0, 3) (1, 4, 0) (1, 3, 1) (1, 2, 2) (1, 1, 3) (1, 0, 4) (0, 5, 0) (0, 4, 1) (0, 3, 2) (0, 2, 3) (0, 1, 4) (0, 0, 5) ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue12961> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com