Re: set, dict and other structures

2005-02-02 Thread Simo Melenius
"Giovanni Bajo" <[EMAIL PROTECTED]> writes: > Just today I was writing some code where I wanted to use sets for > the abstraction (intersection, etc.), but also carry some values > with them to process. So, yes, I believe that having set-like > abstraction for dictionaries would be great. In fact,

Re: set, dict and other structures

2005-02-02 Thread bearophileHUGS
r = {} for x in a: if x not in b: r[x] = r[a] for x in b: if x not in a: r[x] = r[b] I know, this is wrong :-] This looks better: r = {} for x in a: if x not in b: r[x] = a[x] for x in b: if x not in a: r[x] = b[x] Bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: set, dict and other structures

2005-02-02 Thread bearophileHUGS
Leif K-Brooks: >They look exactly the same speed-wise to me: There's a little overhead, you can see it with a bigger test: .from time import clock .n = 1*10**6 . .t1 = clock() .d = set() .for i in xrange(n): . d.add(i) .t2 = clock() .for i in xrange(n): . d.remove(i) .t3 = clock() .d = set(xra

Re: set, dict and other structures

2005-01-31 Thread Jeremy Bowers
On Tue, 01 Feb 2005 00:43:21 +, Raymond Hettinger wrote: > My guess is that there will be two issues. One is that no one > implementation of graphs seems to satisfy all users. The second is that > only a small fraction of Python users need for graph support (there is > probably a much greater

Re: set, dict and other structures

2005-01-31 Thread Giovanni Bajo
Raymond Hettinger wrote: > If set-ifying a dictionary turns out to be an essential and > time-critical operation, it is possible to add some special case code > for this. The question is whether it is worth it. If you find the > need is pressing, file a feature request explaining why it is > es

Re: set, dict and other structures

2005-01-31 Thread bearophileHUGS
You are really gentle Raymond Hettinger, but surely I'm not asking you/anyone to write some code just for me; I don't have "real applications", I'm just learning/playing. Your words are quite good answers to most of my questions. The only left small topic is about the group/set-like operations/meth

Re: set, dict and other structures

2005-01-31 Thread Raymond Hettinger
<[EMAIL PROTECTED]> > I'm frequently using Py2.4 sets, I find them quite useful, and I like > them, even if they seem a little slower than dicts. Glad to hear that you find them to be a useful abstraction. Since sets are internally implemented as dicts, they should have almost identical performan

Re: set, dict and other structures

2005-01-31 Thread Leif K-Brooks
[EMAIL PROTECTED] wrote: I'm frequently using Py2.4 sets, I find them quite useful, and I like them, even if they seem a little slower than dicts. They look exactly the same speed-wise to me: >>> t1 = Timer('randrange(100) in foo', 'from random import randrange; foo = set(xrange(1000))') >>> t2 =