frozendict
Duncan Booth
duncan.booth at invalid.invalid
Thu Feb 9 13:47:20 EST 2012
Nathan Rice <nathan.alexander.rice at gmail.com> wrote:
> As I said, two dictionaries created from the same input will be the
> same... 'ai' != 'ia'. If I need to hash a dict that I don't know was
> created in a deterministic order, I'd frozenset(thedict.items()).
>
Fair enough, the idea scares me, but it's your code and your risk.
BTW, make sure that if you ever copy any of those dictionaries they all get
copied the same number of times as simply copying a dict can change the key
order.
>>> dict.fromkeys('me')
{'e': None, 'm': None}
>>> dict(dict.fromkeys('me'))
{'m': None, 'e': None}
>>> dict(dict(dict.fromkeys('me')))
{'e': None, 'm': None}
--
Duncan Booth http://kupuguy.blogspot.com
More information about the Python-list
mailing list