dictionary with order?

Jp Calderone exarkun at intarweb.us
Fri Mar 14 15:10:15 EST 2003


On Fri, Mar 14, 2003 at 05:39:09PM +0000, York wrote:
> Hi, everybody
> 
> The dictionary in python add a new method -- "setdefault", that is very
> useful.
>
>[snip - python dictionaries are unordered]
> 
> Is it make sense to let a python dictionary arrange its items according to 
> the order that an items be added in? 
> for example, by add a new method "setorder" (d.setorder(1) or 
> d.setorder(-1) for reverse order) to let mothods like keys(), values(), 
> items() return sequence with items order same to the order for these items 
> be added.
> 

  No, it doesn't make sense, because this would require the built-in dict
implementation to do much more work than it does now, for an oft-requested
but rarely necessary feature.

  You can, however, create your own mapping which does have this feature.

  Jp

--
http://catandgirl.com/view.cgi?90
-- 
 up 11 days, 11:59, 7 users, load average: 0.01, 0.04, 0.00





More information about the Python-list mailing list