def limit_data(names, data, limit):
    """ Limit data to the requested number of items, binning the rest into "Other" """
    ret_names = list()
    ret_data = list()

    # Copy unfiltered data
    for idx in range(limit):
        if idx >= len(data):
            break

        ret_names.append(names[idx])
        ret_data.append(data[idx])

    # Aggregate filtered data
    otherSize = 0.0
    for idx in range(limit, len(data)):
        otherSize += float(data[idx])

    if limit < len(data):
        ret_names.append("Other")
        ret_data.append(otherSize)

    return ret_names, ret_data