Re: set of sets



Matteo Dell'Amico wrote:
Paolino wrote:

I thought rewriting __hash__ should be enough to avoid mutables problem but:

class H(set):
 def __hash__(self)
   return id(self)

s=H()

f=set()

f.add(s)
f.remove(s)

the add succeeds
the remove fails eventually not calling hash(s).


Why don't you just use "frozenset"?

And mostly with sets remove operation expense should be sublinear or am
I wrong?
Is this fast as with lists?
Obviously if I use the ids as hash value nothing is guaranted about the
objects contents to be unique but I don't care.
My work is a self organizing net,in which the nodes keep a structure to
link other nodes.As the nature of the net,the links are moved frequently
 so remove and add operations and contains query should be optimized.
Why objects need to be hashable for this? Isn't __hash__ there to solve
the problem?
PS Looks like the problem is not present in class sets.Set





___________________________________ Yahoo! Mail: gratis 1GB per i messaggi e allegati da 10MB http://mail.yahoo.it
.




Relevant Pages

  • Re: set of sets
    ... def __hash__return id ... the add succeeds ... the remove fails eventually not calling hash. ...
    (comp.lang.python)
  • Re: set of sets
    ... def __hash__return id ... the add succeeds ... the remove fails eventually not calling hash. ...
    (comp.lang.python)
  • Re: GRACE WAS A REALITY ONCE..DONT MISS THIS ONE..!
    ... 400 words on your hope for the Obama presidency, ... aisle who have caved and who say, "Well, I hope he succeeds. ... what is unfair about my saying I hope liberalism fails? ... Liberalism is our problem. ...
    (alt.vacation.las-vegas)
  • Re: GNAT parameter passing, C-style?
    ... In vanilla C, there are no argument lists in function ... declarations. ... unconverted argument list is assumed to be OK, the calling convention is ...
    (comp.lang.ada)
  • Re: Tirade Tuesday: telemarketers and Bellsouths "Privacy Director"
    ... dwight wrote: ... keep calling back when I explicitly reject their call. ... I do some marketing myself, and I'm familiar with the Direct Marketing Association. ... All of their members and affiliates pay careful attention to the do not call lists, and any marketer that is calling someone they know to be on that list deserves what they get. ...
    (rec.autos.makers.ford.mustang)