[Tutor] list of dicts <-> dict of lists?

Matthew Wood woodm1979 at gmail.com
Fri May 28 04:00:46 CEST 2010


Wow.  Something horrible happened here.

http://xkcd.com/386/


I THOUGHT the guaranteed same-ordering of dict.keys and dict.values started
in python 2.6.  That was a simple mistake.

It turns out, that's not the case.  But in general, access to dicts and sets
is unordered, so you can't/don't/shouldn't count on ordering.  The solution
to take keys and values from dict.items() DOES guarantee their ordering,
even if dict.keys and dict.values aren't.

That's all I was trying to say.  It's unfortunate that I had the python
version  the guaranteed same-ordering wrong.


I'm certainly not trying to say that you shouldn't trust language features.
 That's not it at all.

But imagine if that guaranteed behavior started in 2.5 for example.  Then,
if you want your code to work on 2.3, you'd definitely want to pull them out
of the dict via dict.items().



I think your response was quite rude.  I mean really, cargo cult
programming?  May John Frum forgive your unnecessary aggression.  I just
tried to suggest a solution and I think it's crappy that you accused me of
"programming without understanding what you are doing".

I recognize that you told me not to take offense; but, no offense, nobody
cared when Carrie Prejean (Miss California) said that either.



So, I do apologize for the mistake I made, and hopefully we (both you AND I)
can nip this mailing-list flame-war in the bud.



Anyway, I hope David (the original questioner) got a little help, or at
least another token for confirmation that any list comprehension solution
will be semi-ugly/semi-complex.


--

I enjoy haiku
but sometimes they don't make sense;
refrigerator?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100527/b70b4a1f/attachment.html>


More information about the Tutor mailing list