[Python-Dev] Another case for frozendict (original) (raw)
Russell E. Owen rowen at uw.edu
Wed Jul 16 01:48:48 CEST 2014
- Previous message: [Python-Dev] Another case for frozendict
- Next message: [Python-Dev] Another case for frozendict
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
In article <CAPTjJmoZHLfT3G4eqV+=ZCVbpf65fkcmah9h_8p162UHA7fQLA at mail.gmail.com>, Chris Angelico <rosuav at gmail.com> wrote:
On Mon, Jul 14, 2014 at 12:04 AM, Jason R. Coombs <jaraco at jaraco.com> wrote: > I can achieve what I need by constructing a set on the ‘items’ of the dict. > >>>> set(tuple(doc.items()) for doc in res) > > {(('n', 1), ('err', None), ('ok', 1.0))}
This is flawed; the tuple-of-tuples depends on iteration order, which may vary. It should be a frozenset of those tuples, not a tuple. Which strengthens your case; it's that easy to get it wrong in the absence of an actual frozendict.
I would love to see frozendict in python.
I find myself using dicts for translation tables, usually tables that should not be modified. Documentation usually suffices to get that idea across, but it's not ideal.
frozendict would also be handy as a default values for function arguments. In that case documentation isn't enough and one has to resort to using a default value of None and then changing it in the function body.
I like frozendict because I feel it is expressive and adds some safety.
-- Russell
- Previous message: [Python-Dev] Another case for frozendict
- Next message: [Python-Dev] Another case for frozendict
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]