Advertisement
zcutlip

duplicate keys in python dictionary

Dec 5th, 2018
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.42 KB | None | 0 0
  1. >>> class Foo(object):
  2. ... pass
  3. ...
  4. >>> myfoo=Foo()
  5. >>> myfoo.url="google.com"
  6. >>> mydict={myfoo:"myfoo all up in there"}
  7. >>>
  8. >>> def new_hash(self):
  9. ... return hash(self.url)
  10. ...
  11. >>> Foo.__hash__=new_hash
  12. >>>
  13. >>> mydict[myfoo]="myfoo all up in there again!!!"
  14. >>> mydict
  15. {<__main__.Foo object at 0x1050e8cd0>: 'myfoo all up in there again!!!', <__main__.Foo object at 0x1050e8cd0>: 'myfoo all up in there'}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement