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
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
>
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
Larry Bates wrote:
I received my copy on Friday (because I was a contributor).
I wanted to thank Alex, Anna, and David for taking the time to put
this together. I think it is a GREAT resource, especially for
beginners. This should be required reading for anyone that
is serous about learning Pytho
George Sakkis wrote:
I'm sure there must have been a past thread about this topic but I don't know
how to find it: How
about extending the "for in" syntax so that X can include default arguments
? This would be very
useful for list/generator comprehensions, for example being able to write
somet
Kay Schluehr wrote:
I think that's because you have to instantiate a different object for
each different key. Otherwise, you would instantiate just one list as
a default value for *all* default values.
Or the default value will be copied, which is not very hard either or
type(self._default)() will
Kay Schluehr wrote:
Why do You set
d.defaultValue(0)
d.defaultValue(function=list)
but not
d.defaultValue(0)
d.defaultValue([])
?
I think that's because you have to instantiate a different object for
each different key. Otherwise, you would instantiate just one list as a
default value for *all* d
Raymond Hettinger wrote:
I would like to get everyone's thoughts on two new dictionary methods:
def count(self, value, qty=1):
try:
self[key] += qty
except KeyError:
self[key] = qty
def appendlist(self, key, *values):
nghoffma wrote:
sorry, that should have been:
py>>import sets
py>>def doit(thelist):
... s = sets.Set(thelist)
... if s == sets.Set([None]):
... return None
... else:
... return max(s - sets.Set([None]))
Since a function that doesn't return is equivalent to one
Luis M. Gonzalez wrote:
Hi there,
I'd like to know if there is a way to add and else condition into a
list comprehension. I'm sure that I read somewhere an easy way to do
it, but I forgot it and now I can't find it...
for example:
z=[i+2 for i in range(10) if i%2==0]
what if I want i to be "i-2" if
10 matches
Mail list logo