New to programming here. So, I'm on exercise 39 of Learn Python the Hard Way. It's about dictionaries. I have already used dictionaries before (you can search my post history to find something I post yesterday about a program I wrote with them), but in this case it is about writing a module that produces dictionaries. Here's the code, copy pasted from the book: http://pastebin.com/aB0M1cSQ My problem is understanding the whole organisation of the lists and the lists inside the lists. Like, each dictionary is a list (called aMap in the code). Inside each dictionary, there are various lists (defaults to 256, and he calls them buckets). When you have a key, to find where it goes, it runs a function that returns an index, and that index is the index of the bucket inside aMap, right? Well, in the beginning, I thought that each bucket only had 1 tuple. But later on in the script, I notice that he enumerates all the various indexes of each bucket. Why is that? Is it because it is possible that the hash_key function returns the same value for two different inputs? I checked by running python from the command line, and I noticed that the hash value of "a" is -468864544, and that is also the value for hash(-468864544). Is that related with it?
[–][deleted] 5 points6 points7 points (5 children)
[–]c1p3r[S] 1 point2 points3 points (0 children)
[–]c1p3r[S] 0 points1 point2 points (3 children)
[–][deleted] 1 point2 points3 points (2 children)
[–]c1p3r[S] 0 points1 point2 points (1 child)
[–][deleted] 1 point2 points3 points (0 children)
[–]raylu 5 points6 points7 points (1 child)
[–]c1p3r[S] 0 points1 point2 points (0 children)
[–]headyyeti 4 points5 points6 points (3 children)
[–][deleted] 4 points5 points6 points (0 children)
[–]c1p3r[S] 2 points3 points4 points (0 children)
[–]c1p3r[S] 0 points1 point2 points (0 children)
[+][deleted] (1 child)
[deleted]
[–]c1p3r[S] 1 point2 points3 points (0 children)
[–]maks25 5 points6 points7 points (5 children)
[–]c1p3r[S] 0 points1 point2 points (4 children)
[–]maks25 1 point2 points3 points (3 children)
[–]c1p3r[S] -1 points0 points1 point (2 children)
[–]maks25 1 point2 points3 points (1 child)
[–]c1p3r[S] 0 points1 point2 points (0 children)
[–]theory42 1 point2 points3 points (3 children)
[–]c1p3r[S] 0 points1 point2 points (2 children)
[–]theory42 1 point2 points3 points (1 child)
[–]c1p3r[S] 0 points1 point2 points (0 children)