[Tutor] id()

Benoit Dupire bdupire@seatech.fau.edu
Thu, 26 Apr 2001 18:10:52 -0400


Benoit Dupire wrote:

>
> I don't think there is another way to do it...
>
> my_list = []
> reverse_id_dict={}
> for i in range(1,5):
>     obj = MyClass()
>     my_list.append( obj)
>     reverse_id_dict[id(obj)] = obj
>

actually i realize my_list is no use if you store the references in a dictionary.
this is better :

reverse_id_dict{}
for i in range(1,5):
    obj = MyClass()
    reverse_id_dict[id(obj)] = obj