|
![](/i/fill.gif) |
Kevin Wampler wrote:
> would give me {"a":"foo", "b":"bar", "c":"baz"} where the order matters
> so D[1] gives "bar"?
It has been a while, but I think so, yes.
> If so, then what happens in the following case:
IIRC, if you use integer keys, you get what you'd expect.
Note that you can iterate over a list without giving specific indexes, so it
might work that you say
foreach key, value in D {print key,value}
and you get
3 foo / 2 bar / 1 baz
or something like that. It has been too long for me to remember.
> said I do sometimes like the C++ stl approach of maintaining an ordering
> in a map based on the natural order of its elements.
That's another way to do it. Or at least make hashes with equal contents
iterate in identical order.
> I actually have used this in python a few times, using a custom class
> rather than a straight dict of course. Unfortunately I can't remember
> why I needed it.
If you're making a dict (in particular a class namespace) that you're going
to translate into (for example) SOAP or a COM interface or something, I can
see where it would be helpful. That's what some of the Python 3.0
extensions were about.
--
Darren New, San Diego CA, USA (PST)
There's no CD like OCD, there's no CD I knoooow!
Post a reply to this message
|
![](/i/fill.gif) |