def uniquify_contacts(contacts):
    """
    Return a sequence of contacts with all duplicates removed.

    If any duplicate names are found without matching numbers, an exception is raised.
    """
    ctd = {}
    for ct in contacts:
        stored_ct = ctd.setdefault(ct.name, ct)
        if stored_ct.dmrid != ct.dmrid:
            raise RuntimeError(
                "Two contacts named {} have different IDs: {} {}".format(
                    ct.name, ct.dmrid, stored_ct.dmrid
                )
            )
    return list(ctd.values())