sorteddict PEP proposal [started off as orderedict]
Mark Summerfield
mark at qtrac.eu
Tue Sep 25 06:40:53 EDT 2007
On 2007-09-25, Andrew Durdin wrote:
> On 9/25/07, Mark Summerfield <m.n.summerfield at googlemail.com> wrote:
> > Since the sorteddict's data is always kept in key order, indexes
> > (integer offsets) into the sorteddict make sense. Five additional
> > methods are proposed to take advantage of this:
> >
> > key(index : int) -> value
> >
> > item(index : int) -> (key, value)
> >
> > value(index : int) -> key
> >
> > set_value(index : int, value)
> >
> > delete(index : int)
>
> But what about using non-sequential integer keys (something I do quite
> often)?
>
> e.g. sorteddict({1:'a', 3:'b': 5:'c', 99:'d'})[3] should return 'b', not
> 'd'.
>
> Andrew
Hmmm, managed to confuse myself with 'b' and 'd'!
d = sorteddict({1:"one", 3:"three", 5:"five", 99:"ninetynine"})
d.items()
[(1, 'one'), (3, 'three'), (5, 'five'), (99, 'ninetynine')]
d[3], d.value(3)
('three', 'ninetynine')
So using [] returns the value for the given key and using value()
returns the value for the given index position.
--
Mark Summerfield, Qtrac Ltd., www.qtrac.eu
More information about the Python-list
mailing list