On 2007-09-25, Andrew Durdin wrote: > On 9/25/07, Mark Summerfield <[EMAIL PROTECTED]> 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
The sorteddict really does work in key order, so: d = sorteddict({1:'a', 3:'b', 5:'c', 99:'d'}) d.items() [(1, 'a'), (3, 'b'), (5, 'c'), (99, 'd')] If you do d[3] you will get 'd' since that is the 4th sequential item. If you want to get the item with _key_ 3 then use value(): d.value(3) 'd' PS In my previous reply I got my example wrong a second time: should have been: for item in itemsByDate.values():... -- Mark Summerfield, Qtrac Ltd., www.qtrac.eu -- http://mail.python.org/mailman/listinfo/python-list