Python: How do sets work
- by Guy
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?