[CentralOH] CentralOH Digest, Vol 91, Issue 17

timothy spencer smashing_good_show at hotmail.com
Wed Nov 26 21:15:11 CET 2014


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. 

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


More information about the CentralOH mailing list