Python: How do sets work

Posted by Guy on Stack Overflow See other posts from Stack Overflow or by Guy
Published on 2010-03-28T08:59:30Z Indexed on 2010/03/28 9:03 UTC
Read the original article Hit count: 257

Filed under:
|
|

I have a list of objects which I want to turn into a set. My objects contain a few fields that some of which are o.id and o.area. I want two objects to be equal if these two fields are the same. ie: o1==o2 if and only if o1.area==o2.area and o1.id==o2.id.

I tried over-writing __eq__ and __cmp__ but I get the error: TypeError: unhashable instance.

What should I over-write?

© Stack Overflow or respective owner

Related posts about python

Related posts about set