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


Groups > comp.lang.python > #39180

Re: Dictionaries with tuples or tuples of tuples

Date 2013-02-18 22:56 -0500
From Mitya Sirenef <msirenef@lightbird.net>
Subject Re: Dictionaries with tuples or tuples of tuples
References (1 earlier) <mailman.1990.1361237726.2939.python-list@python.org> <3752f235-1542-44c8-b7c7-93dfd98eac3f@googlegroups.com> <dc54beb6-3949-4ab3-9c3d-90d264faa1e2@googlegroups.com> <5122E95B.1070600@lightbird.net> <5122EDFD.8000200@davea.name>
Newsgroups comp.lang.python
Message-ID <mailman.2004.1361246208.2939.python-list@python.org> (permalink)

Show all headers | View raw


On 02/18/2013 10:14 PM, Dave Angel wrote:
> On 02/18/2013 09:54 PM, Mitya  Sirenef wrote:
 >> On 02/18/2013 09:17 PM, Jon Reyes wrote:
 >>> Thanks Dave and Mitya for enlightening me about dictionaries. I'm
 >>> still confused about this though:
 >> >
 >> > " so that if two
 >> > key objects are equal, they stay equal, and if they differ, they stay
 >> > different. "
 >> >
 >> > What does this mean? I won't be comparing key objects with one
 >> another. Also, when I had two keys with the same value the value of the
 >> other key disappeared so I assume in runtime if there are multiple keys
 >> of the same value only the last one will appear.
 >>
 >> You won't be, but dict will.
 >>
 >> Dict is by definition a mapping where a value is assigned to a unique
 >> key. If you have two keys and two values, and then change one key to
 >> be equal to the second key, that's not kosher, because which value it's
 >> supposed to return when you try to get it by that key?
 >>
 >> So in effect, key's hash value should not change. If key is immutable,
 >> you can be certain that it's hash value will not change. If it's
 >> mutable, you have to make sure not to change the key in a way that'd
 >> make its hash value different than it was.
 >>
 >> -m
 >>
 >
 > It's a little stronger than that, since equal hashes cannot assure
 > equal data. The equality of each object pair in a dict must not
 > change over time, not just the hashes of the individual objects.
 >

Ah, yes - that's true; if hashes were unequal and then the key is
changed to be equal to the first key, both mydict[key1] and mydict[key2]
will give you value1, but iterating over dict items will print key1,
value1; key2, value2. And that's not a good thing.  -m


-- 
Lark's Tongue Guide to Python: http://lightbird.net/larks/

True friends stab you in the front.
Oscar Wilde

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


Thread

Dictionaries with tuples or tuples of tuples Jon Reyes <everystepsayes@gmail.com> - 2013-02-18 16:52 -0800
  Re: Dictionaries with tuples or tuples of tuples Mitya Sirenef <msirenef@lightbird.net> - 2013-02-18 20:11 -0500
    Re: Dictionaries with tuples or tuples of tuples Jon Reyes <everystepsayes@gmail.com> - 2013-02-18 17:19 -0800
    Re: Dictionaries with tuples or tuples of tuples Jon Reyes <everystepsayes@gmail.com> - 2013-02-18 17:19 -0800
  Re: Dictionaries with tuples or tuples of tuples Roy Smith <roy@panix.com> - 2013-02-18 20:17 -0500
    Re: Dictionaries with tuples or tuples of tuples Jon Reyes <everystepsayes@gmail.com> - 2013-02-18 17:20 -0800
  Re: Dictionaries with tuples or tuples of tuples Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-02-19 01:37 +0000
    Re: Dictionaries with tuples or tuples of tuples Jon Reyes <everystepsayes@gmail.com> - 2013-02-18 17:38 -0800
      Re: Dictionaries with tuples or tuples of tuples Dave Angel <davea@davea.name> - 2013-02-18 20:51 -0500
      Re: Dictionaries with tuples or tuples of tuples Mitya Sirenef <msirenef@lightbird.net> - 2013-02-18 20:56 -0500
      Re: Dictionaries with tuples or tuples of tuples Jon Reyes <everystepsayes@gmail.com> - 2013-02-18 18:17 -0800
        Re: Dictionaries with tuples or tuples of tuples Mitya Sirenef <msirenef@lightbird.net> - 2013-02-18 21:54 -0500
        Re: Dictionaries with tuples or tuples of tuples Dave Angel <davea@davea.name> - 2013-02-18 22:14 -0500
        Re: Dictionaries with tuples or tuples of tuples Mitya Sirenef <msirenef@lightbird.net> - 2013-02-18 22:56 -0500
      Re: Dictionaries with tuples or tuples of tuples Jon Reyes <everystepsayes@gmail.com> - 2013-02-18 18:17 -0800
      Re: Dictionaries with tuples or tuples of tuples Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-02-19 02:34 +0000
        Re: Dictionaries with tuples or tuples of tuples Jon Reyes <everystepsayes@gmail.com> - 2013-02-18 18:39 -0800
        Re: Dictionaries with tuples or tuples of tuples Jon Reyes <everystepsayes@gmail.com> - 2013-02-18 18:39 -0800
    Re: Dictionaries with tuples or tuples of tuples Jon Reyes <everystepsayes@gmail.com> - 2013-02-18 17:38 -0800

csiph-web