Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #20081

Re: frozendict

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <nathan.alexander.rice@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.055
X-Spam-Evidence '*H*': 0.89; '*S*': 0.00; '>>>>': 0.09; 'dict': 0.09; 'appropriate)': 0.16; 'dictionaries': 0.16; '\xa0as': 0.16; 'cc:addr:python-list': 0.16; 'insert': 0.19; 'cc:no real name:2**0': 0.21; 'input': 0.22; 'header:In-Reply-To:1': 0.22; 'appear': 0.23; 'calls.': 0.23; 'cc:2**0': 0.26; 'order.': 0.28; 'message-id:@mail.gmail.com': 0.29; 'fine.': 0.29; 'cc:addr:python.org': 0.29; '(and': 0.30; 'hash': 0.30; 'none,': 0.30; 'received:209.85.210.46': 0.30; 'received:mail- pz0-f46.google.com': 0.30; 'values': 0.32; 'keys': 0.34; 'two': 0.36; 'sequence': 0.37; 'created': 0.37; 'but': 0.37; 'received:google.com': 0.37; 'received:209.85': 0.38; "i'd": 0.39; 'received:209': 0.39; 'your': 0.61; 'guarantee': 0.66; 'order,': 0.73; 'guaranteed': 0.77; 'nathan': 0.84; 'order:': 0.91
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; bh=rvF4PTgLXYXI+FoA9of8U0mE//ZEl7XFkPDIrPzUW0o=; b=ivSjkSpeTiqbN2uoDOJEckYVlqxd3y/TJPUDnOGiHnk3gU/TcysOmQpUjfWjuLDrp2 GiRgEdrVIhTbq0uySZn/gFhuAwSKfBehSJMCf98VjH3ioVefyh6TgrNVKUIXzDTzlUEG ji5g3Nf1a7qw10WPQSd99irBUtWonQ3bN1zb8=
MIME-Version 1.0
In-Reply-To <Xns9FF497406322duncanbooth@127.0.0.1>
References <4F332007.9080800@wisc.edu> <jgv9ps$35g$1@dough.gmane.org> <mailman.5558.1328759017.27778.python-list@python.org> <Xns9FF46B35EDFF9duncanbooth@127.0.0.1> <mailman.5588.1328798176.27778.python-list@python.org> <Xns9FF497406322duncanbooth@127.0.0.1>
Date Thu, 9 Feb 2012 10:19:46 -0500
Subject Re: frozendict
From Nathan Rice <nathan.alexander.rice@gmail.com>
To duncan.booth@suttoncourtenay.org.uk
Content-Type text/plain; charset=ISO-8859-1
Content-Transfer-Encoding quoted-printable
Cc python-list@python.org
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.5593.1328800790.27778.python-list@python.org> (permalink)
Lines 28
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1328800790 news.xs4all.nl 6975 [2001:888:2000:d::a6]:39890
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:20081

Show key headers only | View raw


>> Two dicts created from the same inputs will return items in the same
>> arbitrary order.  As long as you don't insert or delete a key you're
>> fine.
>>
> Two dicts that contain the same keys and values may or may not return them
> in the same order:
>
>>>> dict.fromkeys('ia')
> {'i': None, 'a': None}
>>>> dict.fromkeys('ai')
> {'a': None, 'i': None}
>
> Would your system count those two dicts as the same?
>
> If the sequence in which the keys were added to the dict (and deleted if
> appropriate) is exactly the same then it is likely but still not guaranteed
> that they will have the same order. The only ordering guarantee is that
> within a single dict keys and values will appear in a consistent order so
> long as you don't add/delete keys between calls.

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()).


Nathan

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Re: frozendict Nathan Rice <nathan.alexander.rice@gmail.com> - 2012-02-08 22:43 -0500
  Re: frozendict Duncan Booth <duncan.booth@invalid.invalid> - 2012-02-09 10:33 +0000
    Re: frozendict Nathan Rice <nathan.alexander.rice@gmail.com> - 2012-02-09 09:36 -0500
      Re: frozendict Duncan Booth <duncan.booth@invalid.invalid> - 2012-02-09 14:52 +0000
        Re: frozendict Nathan Rice <nathan.alexander.rice@gmail.com> - 2012-02-09 10:19 -0500
          Re: frozendict Duncan Booth <duncan.booth@invalid.invalid> - 2012-02-09 18:47 +0000
        Re: frozendict Ian Kelly <ian.g.kelly@gmail.com> - 2012-02-09 09:35 -0700
          Re: frozendict Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-02-10 01:24 +0000
            Re: frozendict Nathan Rice <nathan.alexander.rice@gmail.com> - 2012-02-09 21:30 -0500
            Re: frozendict Terry Reedy <tjreedy@udel.edu> - 2012-02-09 22:33 -0500
            Re: frozendict Chris Angelico <rosuav@gmail.com> - 2012-02-10 21:08 +1100
            Re: frozendict Nathan Rice <nathan.alexander.rice@gmail.com> - 2012-02-10 11:53 -0500
            Re: frozendict Chris Rebert <clp2@rebertia.com> - 2012-02-10 09:00 -0800
            Re: frozendict Nathan Rice <nathan.alexander.rice@gmail.com> - 2012-02-10 13:14 -0500
              Re: frozendict John Nagle <nagle@animats.com> - 2012-02-10 10:57 -0800
                Re: frozendict 88888 Dihedral <dihedral88888@googlemail.com> - 2012-02-10 21:52 -0800
                Re: frozendict John Nagle <nagle@animats.com> - 2012-02-13 13:15 -0800
        Re: frozendict Nathan Rice <nathan.alexander.rice@gmail.com> - 2012-02-09 11:50 -0500

csiph-web