Confusion about dictionaries - keys use value or identity?
sholden at holdenweb.com
Sun Jul 8 18:38:36 EDT 2001
"Tim Peters" <tim.one at home.com> wrote in message
news:mailman.994626808.10039.python-list at python.org...
> [Steve Holden]
> > ...
> > Key comparison of strings will test the lengths fisrt, and if the
> > lengths are the same will stop once two unequal characters are found...
> That's backwards. If it tested the lengths first, then e.g. "z" < "aaa"
> would be true.
> "perl"<"python"-is-true-either-way-though-ly y'rs - tim
We are talking about has_key here, right?
I was simply trying (perhaps rather too hurriedly, as it turned out) the
fact that strings if unequal lengths could not be equal, and only equality
is required when indexing a dictionary. Without looking at the code I'm
presuming that actually some fairly crafty hashing algorithm is used to test
for the presence of a particular key. But when more that one entry hashes to
the same bucket, I hope the lengths are checked before
character-by-character comparison goes ahead ... you know the details, I
don't, so I'm not going to press this issue any further. And no, I haven't
forgotten that strings are only a subset of the possible keys.
Which is why I said "key comparison of strings". I know you know that
locating a dicitonary entry isn't the same thing as comparing strings
and-we-all-assume-python>perl-anyway-ly y'rs - steve
More information about the Python-list