[Python] Is there a python datastructure for "set" unique by id? [duplicate]

Discussão em 'Python' iniciado por Stack, Junho 25, 2025.

  1. Stack

    Stack Membro Participativo

    Fairly often I want to check that I am not adding the exact same object instance multiple times to a collection. Where I have already made sure that all object instances that are equal are actually just references to the same object.

    In the normal python set only hashable things can be stored. If I wanted a set that compared equality with is and used x->hash(id(x)) as the hash function, how would I do that? This would be safe and correct even for mutable objects.

    In JuliaLang this is the IdSet type

    Continue reading...

Compartilhe esta Página