Re: set of sets

2005-08-11 Thread Matteo Dell'Amico
Paolo Veronelli wrote: > Yes this is really strange. > > from sets import Set > class H(Set): > def __hash__(self): > return id(self) > > s=H() > f=set() #or f=Set() > > f.add(s) > f.remove(s) > > No errors. > > So we had a working implementation of sets in the library an put a > broken

Re: set of sets

2005-08-11 Thread Matteo Dell'Amico
Paolo Veronelli wrote: > And mostly with sets remove operation expense should be sublinear or am > I wrong? > Is this fast as with lists? It's faster then with lists... in sets, as with dicts, remove is on average O(1). > Obviously if I use the ids as hash value nothing is guaranted about the >

Re: set of sets

2005-08-11 Thread Paolo Veronelli
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). > Yes this i

Re: set of sets

2005-08-11 Thread Robert Kern
Paolino wrote: > Matteo Dell'Amico wrote: >>Why don't you just use "frozenset"? > > This is what I'm doing, but the problem remains IMO. > Anyway with frozenset I have to override __new__ instead of __init__ to > make the initialization which is an operation not described in the > frozenset do

Re: set of sets

2005-08-11 Thread Paolo Veronelli
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

Re: set of sets

2005-08-11 Thread Paolino
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

Re: set of sets

2005-08-11 Thread Matteo Dell'Amico
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 yo

set of sets

2005-08-11 Thread Paolino
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). Thanks for help Paolino