import itertools


def get_enumeration_tuples(Z, n):
    """Get all length-n tuples of nonnegative integers which sum to Z."""
    sequences = itertools.product(*[range(Z+1) for _i in range(n)])
    return filter(lambda s: sum(s)==Z, sequences)