<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 12pt;
font-family:Calibri
}
--></style></head>
<body class='hmmessage'><div dir='ltr'>I will bring my questions into the next Dojo for sure. I haven't gotten all the way through Ex 39 yet. One thing that I have learned that is pretty neat from another tutorial is that I can take one list or dictionary, and set that to a key in another dictionary, creating a dictionary within a dictionary, e.g. I still need to read through that Hash Table page in Wikipedia too. <br><br><div>> From: centraloh-request@python.org<br>> Subject: CentralOH Digest, Vol 91, Issue 17<br>> To: centraloh@python.org<br>> Date: Wed, 26 Nov 2014 12:00:01 +0100<br>> <br>> Send CentralOH mailing list submissions to<br>>         centraloh@python.org<br>> <br>> To subscribe or unsubscribe via the World Wide Web, visit<br>>       https://mail.python.org/mailman/listinfo/centraloh<br>> or, via email, send a message with subject or body 'help' to<br>>     centraloh-request@python.org<br>> <br>> You can reach the person managing the list at<br>>   centraloh-owner@python.org<br>> <br>> When replying, please edit your Subject line so it is more specific<br>> than "Re: Contents of CentralOH digest..."<br>> <br>> <br>> Today's Topics:<br>> <br>>    1. Zed's ex39 (jep200404@columbus.rr.com)<br>>    2. Re: CentralOH Digest, Vol 91, Issue 16 (timothy spencer)<br>> <br>> <br>> ----------------------------------------------------------------------<br>> <br>> Message: 1<br>> Date: Tue, 25 Nov 2014 09:15:45 -0500<br>> From: jep200404@columbus.rr.com<br>> To: "Mailing list for Central Ohio Python User Group \(COhPy\)"<br>>    <centraloh@python.org><br>> Subject: [CentralOH] Zed's ex39<br>> Message-ID: <20141125091545.23f4328e.jep200404@columbus.rr.com><br>> Content-Type: text/plain; charset=US-ASCII<br>> <br>> On Mon, 24 Nov 2014 17:14:15 -0800, timothy spencer <smashing_good_show@hotmail.com> wrote:<br>> <br>> > I am on Zed Shaw's book in EX 39, ... <br>> <br>> A URL for that is: <br>> http://learnpythonthehardway.org/book/ex39.html<br>> <br>> > What is a 'bucket'? <br>> <br>> > Is a bucket simply the slot where a pair would go? <br>> <br>> The artful terms bucket and slot should be defined before they <br>> are used. That they are not is an example of how the on-line <br>> tutorials have weaknesses. You should document them in your <br>> source code and bring it to a dojo for discussion and rework. <br>> <br>> The first paragraph on page 25 of Learning Python 5th edition<br>> says in part: <br>> <br>>     When people write software, they are not writing it for <br>>     themselves. In fact, they are not even writing primarily <br>>     for the computer. Rather good programmers know tha the <br>>     code is written for the next human being who has to read <br>>     it in order to maintain or reuse it. If that person cannot <br>>     understand the code, it's all but useless in a realistic <br>>     development scenario. In other words, programming is not <br>>     about being clever and obscure - it's about how clearly <br>>     your program communicates its purpose. <br>> <br>> > I know that a dictionary is a list of 'key: value' pairs. <br>> <br>> That's almost correct. A Python list is ordered. <br>> A Python dictionary is not ordered, <br>> so a Python dictionary is not a list.<br>> <br>> > Like if a dictionary is horizontal, then I am wondering if a <br>> > bucket then is a vertical slot that can have lots of tuples. <br>> <br>> Draw me a picture. ASCII art is good.<br>> <br>> > ... and his description is a little odd.<br>> <br>> His code for hashmap.py is mediocre. There may be good reasons <br>> for the mediocrity in a tutorial, such as serving as an example <br>> of how to do things awkwardly, then showing the better way later. <br>> Does the author improve the code later? <br>> <br>> Here are some of the things I notice. <br>> <br>> That get_slot() returns a copy of the key argument seems <br>> superfluous. The key return value is not used in the two <br>> places that call get_slot(). So don't return the key. <br>> <br>> That line 4 of hashmap.py uses range(0, num_buckets) instead <br>> of range(num_buckets) is odd. What rationale can you think of <br>> for using range(0, num_buckets) instead of range(num_buckets)? <br>> I would just use range(num_buckets). <br>> <br>> It's curious that he uses range() on line 4, but xrange() on <br>> line 53. What's the rationale for using one instead of the other? <br>> <br>> The get_bucket() call on line 39 is redundant with the <br>> get_bucket() call on line 23 when get_slot is called on <br>> line 40. I would have get_slot() return bucket in its <br>> return tuple, and delete line 39. <br>> <br>> How would the code work if line 57 was a return instead of a break? <br>> Which do you prefer? Why? Compare that with line 28. <br>> Compare those with using an else: clause for the for loop.<br>> <br>> What do you think of line 62? Is it necessary? <br>> Does it show that the author does not know how Python <br>> "does nothing" gracefully? Is the author saving this <br>> clutziness for later refactoring or does the author <br>> just write mediocre code? <br>> <br>> Line 25 uses enumerate(). Could you use enumerate() <br>> to combine lines 53 and 54? Would that be an <br>> improvement or make things worse?<br>> <br>> Is xrange(len(foo)) ugly or Pythonic?<br>> <br>> What should delete() do if no "slot" has the key?<br>> <br>> What's a better name for get()? How about get_value? <br>> <br>> bucket_id on line 16 is used as an index. <br>> I.e., bucket_id is not an ID. <br>> It's a feeble name. A better name would be bucket_index. <br>> What name is better yet?<br>> <br>> Most of the free on-line tutorials have weaknesses. <br>> I would say that the documentation is a bit thin, <br>> and his code should be refactored. You should always <br>> be looking for ways that the code could be improved. <br>> What other opportunities for improvement do you see? <br>> <br>> Much code in the real world is worse. <br>> <br>> On Mon, 24 Nov 2014 21:58:04 -0500, pybokeh <pybokeh@gmail.com> wrote:<br>> <br>> > here is a video that I thought was helpful by a great speaker<br>> > / Python core developer named Raymond Hettinger:<br>> > https://www.youtube.com/watch?v=OSGv2VnC0go<br>> <br>> That's a fun video. It covers some of the things I did. <br>> How would one change get_slot() after my changes above <br>> and after watching the video? <br>> <br>> <br>> ------------------------------<br>> <br>> Message: 2<br>> Date: Tue, 25 Nov 2014 06:56:05 -0800<br>> From: timothy spencer <smashing_good_show@hotmail.com><br>> To: "centraloh@python.org" <centraloh@python.org><br>> Subject: Re: [CentralOH] CentralOH Digest, Vol 91, Issue 16<br>> Message-ID: <SNT148-W28A2D35A3DB29B4E7CA211CB730@phx.gbl><br>> Content-Type: text/plain; charset="iso-8859-1"<br>> <br>> I will be looking at those links later today. Thanks for the direction.<br>> <br>> > From: centraloh-request@python.org<br>> > Subject: CentralOH Digest, Vol 91, Issue 16<br>> > To: centraloh@python.org<br>> > Date: Tue, 25 Nov 2014 12:00:02 +0100<br>> > <br>> > Send CentralOH mailing list submissions to<br>> >      centraloh@python.org<br>> > <br>> > To subscribe or unsubscribe via the World Wide Web, visit<br>> >        https://mail.python.org/mailman/listinfo/centraloh<br>> > or, via email, send a message with subject or body 'help' to<br>> >   centraloh-request@python.org<br>> > <br>> > You can reach the person managing the list at<br>> >    centraloh-owner@python.org<br>> > <br>> > When replying, please edit your Subject line so it is more specific<br>> > than "Re: Contents of CentralOH digest..."<br>> > <br>> > <br>> > Today's Topics:<br>> > <br>> >    1. Re: What is a 'bucket'? (Neil Ludban)<br>> > <br>> > <br>> > ----------------------------------------------------------------------<br>> > <br>> > Message: 1<br>> > Date: Mon, 24 Nov 2014 22:32:10 -0500<br>> > From: Neil Ludban <nludban@columbus.rr.com><br>> > To: "Mailing list for Central Ohio Python User Group \(COhPy\)"<br>> >   <centraloh@python.org><br>> > Cc: timothy spencer <smashing_good_show@hotmail.com><br>> > Subject: Re: [CentralOH] What is a 'bucket'?<br>> > Message-ID: <20141124223210.5cd1c929.nludban@columbus.rr.com><br>> > Content-Type: text/plain; charset=US-ASCII<br>> > <br>> > http://en.wikipedia.org/wiki/Hash_table<br>> > <br>> > EX 39 looks like this variation:<br>> > <br>> > http://en.wikipedia.org/wiki/Hash_table#Separate_chaining<br>> > """In the method known as separate chaining, each bucket is independent,<br>> > and has some sort of list of entries with the same index."""<br>> > <br>> > Note that "index" here is defined as the output of the hash function,<br>> > and entries are key,value pairs.<br>> > <br>> > <br>> > Compare with another variation where a bucket is a key,value pair:<br>> > <br>> > http://en.wikipedia.org/wiki/Hash_table#Open_addressing<br>> > <br>> > <br>> > On Mon, 24 Nov 2014 17:14:15 -0800<br>> > timothy spencer <smashing_good_show@hotmail.com> wrote:<br>> > > <br>> > > <br>> > > <br>> > > Hello everyone. What is a 'bucket'? I think that I may be over-thinking this. I know that a dictionary is a list of 'key: value' pairs. Is a bucket simply the slot where a pair would go? I am wondering if a bucket is a slot where multiple tuples would go. Like if a dictionary is horizontal, then I am wondering if a bucket then is a vertical slot that can have lots of tuples. Lists within lists.. Then again, perhaps it is just a slot that only holds one key:value pair. I am on Zed Shaw's book in EX 39, and his description is a little odd.<br>> > > <br>> > > Let me know, thanks,<br>> > > <br>> > > Tim<br>> > >                                                                                    <br>> > <br>> > <br>> > ------------------------------<br>> > <br>> > Subject: Digest Footer<br>> > <br>> > _______________________________________________<br>> > CentralOH mailing list<br>> > CentralOH@python.org<br>> > https://mail.python.org/mailman/listinfo/centraloh<br>> > <br>> > <br>> > ------------------------------<br>> > <br>> > End of CentralOH Digest, Vol 91, Issue 16<br>> > *****************************************<br>>                                           <br>> -------------- next part --------------<br>> An HTML attachment was scrubbed...<br>> URL: <http://mail.python.org/pipermail/centraloh/attachments/20141125/7f4521df/attachment-0001.html><br>> <br>> ------------------------------<br>> <br>> Subject: Digest Footer<br>> <br>> _______________________________________________<br>> CentralOH mailing list<br>> CentralOH@python.org<br>> https://mail.python.org/mailman/listinfo/centraloh<br>> <br>> <br>> ------------------------------<br>> <br>> End of CentralOH Digest, Vol 91, Issue 17<br>> *****************************************<br></div>                                          </div></body>
</html>