Why are there no ordered dictionaries?

Christoph Zwerschke cito at online.de
Wed Nov 23 22:21:59 CET 2005


Bengt Richter wrote:

>  >>> from odictb import OrderedDict
>  >>> d1 = OrderedDict([(1, 11), (2, 12), (3, 13)])
>  >>> d1
>  {1: 11, 2: 12, 3: 13}
>  >>> d1[1:]
>  {2: 12, 3: 13}
>  >>> d1[0:1] + d1[2:3]
>  {1: 11, 3: 13}
>  >>> d1.reverse()
>  >>> d1
>  {3: 13, 2: 12, 1: 11}
>  >>> d1.insert(1, (4,14))
>  >>> d1
>  {3: 13, 4: 14, 2: 12, 1: 11}
>  >>> d1.items()
>  [(3, 13), (4, 14), (2, 12), (1, 11)]
>  >>> d1.keys()
>  [3, 4, 2, 1]
>  >>> d1.values()
>  [13, 14, 12, 11]
>  >>> d1[1:2]
>  {4: 14}
>  >>> d1[-1:]
>  {1: 11}
> 
> Que mas?

Eso es exactamente lo que yo queria haber!

-- Chris



More information about the Python-list mailing list