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


Groups > comp.lang.python > #75518

Re: Dict when defining not returning multi value key error

From Marko Rauhamaa <marko@pacujo.net>
Newsgroups comp.lang.python
Subject Re: Dict when defining not returning multi value key error
Date 2014-08-02 10:06 +0300
Organization A noiseless patient Spider
Message-ID <87vbqbmkv9.fsf@elektro.pacujo.net> (permalink)
References (6 earlier) <mailman.12512.1406901485.18130.python-list@python.org> <87vbqcnrrh.fsf@elektro.pacujo.net> <lrh1jr$u65$1@ger.gmane.org> <mailman.12529.1406937431.18130.python-list@python.org> <87zjfnmlzr.fsf@elektro.pacujo.net>

Show all headers | View raw


Marko Rauhamaa <marko@pacujo.net>:

> Important systems absolutely rely on the fact that the hashes can be
> used for identification. They are not just checksums. They are not
> double-checked with bit-to-bit comparisons of the actual data.

And in fact, you can use the principle in Python:

    class Thingy:
        def __init__(self, ...):
            ...
            self.stronghash = self.compute_strong_hash()
            self.hash = struct.unpack("Q", self.stronghash[:8])[0]

        def __hash__(self):
            return self.hash

        def __eq__(self, other):
            try:
                return self.stronghash == other.stronghash
            except AttributeError:
                return False


Marko

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


Thread

Re: Dict when defining not returning multi value key error Dan Stromberg <drsalists@gmail.com> - 2014-07-31 20:12 -0700
  Re: Dict when defining not returning multi value key error Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-08-01 04:04 +0000
    Re: Dict when defining not returning multi value key error Ben Finney <ben+python@benfinney.id.au> - 2014-08-01 14:17 +1000
      Re: Dict when defining not returning multi value key error Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-08-01 13:31 +0000
        Re: Dict when defining not returning multi value key error Chris Angelico <rosuav@gmail.com> - 2014-08-01 23:57 +1000
          Re: Dict when defining not returning multi value key error Marko Rauhamaa <marko@pacujo.net> - 2014-08-01 18:39 +0300
            Re: Dict when defining not returning multi value key error Terry Reedy <tjreedy@udel.edu> - 2014-08-01 17:42 -0400
            Re: Dict when defining not returning multi value key error Chris Angelico <rosuav@gmail.com> - 2014-08-02 09:57 +1000
              Re: Dict when defining not returning multi value key error Marko Rauhamaa <marko@pacujo.net> - 2014-08-02 09:41 +0300
                Re: Dict when defining not returning multi value key error Marko Rauhamaa <marko@pacujo.net> - 2014-08-02 10:06 +0300
                Re: Dict when defining not returning multi value key error Chris Angelico <rosuav@gmail.com> - 2014-08-02 20:58 +1000
            Re: Dict when defining not returning multi value key error Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-08-02 11:47 +1000
              Re: Dict when defining not returning multi value key error Chris Angelico <rosuav@gmail.com> - 2014-08-02 12:13 +1000

csiph-web