[Python-Dev] PEP 3144 review.

Dj Gilcrease digitalxero at gmail.com
Mon Sep 28 17:30:05 CEST 2009


On Mon, Sep 28, 2009 at 8:56 AM, Guido van Rossum <guido at python.org> wrote:
> Hold it right there! That's wrong. You can't have two objects that
> compare equal but whose hashes differ. It will break dict lookup. The
> other way around is fine: two objects may differ and still have the
> same hash.


mm I never knew that, guess I'll go fix my patch to change the
__hash__ method as well, though when I tested it dict lookup seemed to
work fine


>>> net1 = IPNetwork("10.1.2.0/29")
>>> i = 0
>>> test = {}
>>> for ip in net1:
	test[IPNetwork("%s/29" %(ip))] = i
	i += 1

	
>>> print test[IPv4Network('10.1.2.4/29')]
4
>>> print test
{IPv4Network('10.1.2.0/29'): 0, IPv4Network('10.1.2.1/29'): 1,
IPv4Network('10.1.2.2/29'): 2, IPv4Network('10.1.2.3/29'): 3,
IPv4Network('10.1.2.4/29'): 4, IPv4Network('10.1.2.5/29'): 5,
IPv4Network('10.1.2.6/29'): 6, IPv4Network('10.1.2.7/29'): 7}
>>>


More information about the Python-Dev mailing list