An event log contains repeated item ids. You need the distinct ids in the order they first appeared, the ids that repeated, and the distinct ids ordered by a priority table.
Write dedupe_and_rank(items, priority) that returns a tuple (unique, repeated, ranked) of three lists.
items: a list of hashable values (strings, ints, tuples), possibly empty.priority: a dictionary mapping some values to numeric priorities (lower comes first).unique: each distinct value once, in order of first appearance.repeated: the values that appear more than once, each listed once, in the order in which their second occurrence appears.ranked: the values of unique sorted by ascending priority. Values with equal priority keep their order from unique. Values missing from priority go after all prioritised values, also in their order from unique.Run in time where is the number of distinct values.