On Mar 1, 2007, at 3:18 PM, Chris Withers wrote:
Gary Poster wrote:
Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: argument to reversed() must be a sequence
The fact that this works for the OOSet is an implementation accident.
As discussed elsewhere in this thread, sets are not sequences.
The fact that the elements are ordered is an implementation detail
(although given that these sets are essentially the keys of a
BTree, it's unsurprising that they are).
You could argue that reversed(OOSet((1,2,3))) should raise an
exception. IMO, why bother.
Okay, so I want a persistent, ordered sequence which is quick to
find items in and which doesn't re-store the whole sequence when an
item is inserted or removed.
What should I be using?
Ordered, as in sorted? Or ordered, as in user-determined order?
If sorted, use BTreeSet (or the keys of a BTree). Even though my
assertion is right semantically for "Set", this is a BTreeSet, and I
don't see this behavior changing ever. No, it isn't a sequence, so
`reversed` won't work, but `list` will always give you the same
order. "Set" does not match the "doesn't re-store the whole
sequence when an item is inserted or removed" requirement.
If user-determined (like a list) then you are currently out of luck.
I actually have a implementation of this (which I think is cool) with
some tests, but I regard it as experimental and am refactoring it in
my spare (ha) time. (I would not mind you looking at what I have,
but I don't particularly recommend it yet for production, so I expect
it is useless to you.)
In both cases, IMO you'll want your data to be of homogenous types.
Zope-Dev maillist - Zope-Dev@zope.org
** No cross posts or HTML encoding! **
(Related lists -