[python-uk] memoize & ordering of kwargs.items()
Alexander Harrowell
a.harrowell at gmail.com
Fri Nov 11 13:54:10 CET 2011
On Friday 11 Nov 2011 09:30:23 Jonathan wrote:
> I agree that 'to be sure' is enough of a justification for including
the 'sorted' call anyway. But it irks me that I can't write a test to
show it.
This is surely inherent in the fact that python dictionaries are not
deterministically ordered. The dox don't say that you will always get
key-val pairs back in *different* orders - just that you cannot rely on
them being in the *same* order. Equally, you can't assume that they
*won't*.
Further, the dox also suggest that the behaviour is not truly random, so
you can't rely on statistical randomness. You just have to avoid the
whole idea of order when retrieving items from a python dictionary and
treat it purely as a hash table that supports both a get-item-by-id
behaviour and also some iterative and setwise methods.
ISTR there are cases where two calls to dict.items() (and dict.keys()
and dict.values()) *will* get the same order if there was no intervening
write to the dict, but I suspect it's best to stick to the "right"
behaviour.
--
The only thing worse than e-mail disclaimers...is people who send e-mail
to lists complaining about them
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-uk/attachments/20111111/fe1d1c8b/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part.
URL: <http://mail.python.org/pipermail/python-uk/attachments/20111111/fe1d1c8b/attachment.pgp>
More information about the python-uk
mailing list