access dictionary with preferred order ?

bonono at gmail.com bonono at gmail.com
Sat Oct 22 01:21:01 EDT 2005


thanks. But I do quite understand how to specific my order(which could
be arbitary). It seems to have a move method so I need to first loop
through my order list and match then move things around ?

James Stroud wrote:
> This is an "ordered dict":
>
>    http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/438823
>
> On Friday 21 October 2005 21:18, bonono at gmail.com wrote:
> > Hi,
> >
> > I am wondering if there is a dictionary data type that allows me to
> > define the order of access when iterating it using items/keys etc. ?
> >
> > An example:
> >
> > a=dict(a=dict(), c=dict(), h=dict())
> > prefer=['e','h', 'a']
> >
> > for x in a.values: print x
> >
> > would give me
> > {h:dict()}, {a:dict()}, then the rest which I don't care about the
> > order ?
>
> --
> James Stroud
> UCLA-DOE Institute for Genomics and Proteomics
> Box 951570
> Los Angeles, CA 90095
> 
> http://www.jamesstroud.com/




More information about the Python-list mailing list