def partition_list(Z, L):
    """Returns a dictionary partitioning list L according to assignments in Z.

    Example:
    >>> Z = {0:0, 1:2, 2:7, 3: 7, 4:0}
    >>> L = [2, 1, 0, 4, 3]
    >>> partition_list(Z, L)
    {0:[0, 4], 2:[1], 7:[2, 3]}
    """
    result = {}
    for l in L:
        k = Z[l]
        if k in result:
            result[k].append(l)
        else:
            result[k] = [l]
    return result