def update_labels(items, labels):
    """Update a list of integers of the same length based on the duplicates in
    another list of integers. If an item is duplicated in the list of items,
    that means they are labeled using different integers in the list of labels.
    This assigns the same int/label (the label of the first occurrence) to
    all of the items that are labeled with those integers. Note that this can
    be more than just the duplicates we first found in the list of items.

    Parameters
    ----------
    items : int list or int array
        The list of items.
    labels : int list or int array
        The list of labels.

    Returns
    -------
    labels: int list or int array
        Updated labels.

    Example
    -------
    >>> items = np.array([7, 2, 0, 6, 0, 4, 1, 5, 2, 0])
    >>> labels = np.array([1, 0, 3, 4, 2, 1, 6, 6, 5, 4])
    >>> update_labels(items, labels)
    [1 0 3 4 3 1 6 6 0 3]
    """

    i_dict, l_dict, ranks = {}, {}, {}

    for i in range(len(items)):
        label = i_dict.setdefault(items[i], labels[i])
        if labels[i] not in ranks:
            ranks[labels[i]] = i

        if label != labels[i]:
            label1 = label
            label2 = labels[i]
            while label1 is not None and label2 is not None:
                if ranks[label1] > ranks[label2]:
                    tmp = l_dict.get(label1)
                    l_dict[label1] = label2
                    label1 = tmp
                elif ranks[label1] < ranks[label2]:
                    tmp = l_dict.get(label2)
                    l_dict[label2] = label1
                    label2 = tmp
                else:
                    break

            labels[i] = label

    for i in range(len(labels)):
        val = 0
        label = labels[i]
        while val != -1:
            val = l_dict.get(label, -1)
            if val != -1:
                label = val
        if label != labels[i]:
            labels[i] = label

    return labels