Re: [Tutor] Making Doubly Linked List with Less Lines of Code.
Thanks, definitely adding this concept into my code. And re-writing. I originally hard coded everything just to get it working... but obviously, it would have been more time efficient to have thought in these terms from the beginning. Hopefully I can learn to write code more like this to begin with, even when I just want to get something working. Reading the rest of your recommendations now. On 12/25/2014 12:15 AM, Danny Yoo wrote: Quick comment: the structure of the code here catches my eye: # Each variable below is a link to the head Node in the respective # row or column. self.row0 = None self.row1 = None self.row2 = None self.row3 = None self.row4 = None self.row5 = None self.row6 = None self.row7 = None self.row8 = None self.row9 = None It seems highly regular; the code here is maintaining a collection of row variables. Because it's so regular, you might consider using a list to represent this collection. Concretely: self.rows = [None, None, None, None, None, None, None, None, None, None] We can express this more concisely in Python as: self.row = [None] * 10 Once we have this, then we can get at any particular row through its offset. So instead of: self.row0 we say: self.row[0] The big win with a list representation is that the offset can be computed. So if we need to do an operation on each row, we might say: for i in range(10): ## ... Do something with self.row[i] And if you see the full power of this, you'll realize that this allows us to express loops to do something to _all_ the rows, expressing that action just once. Or if we need to do something for every other row, that too is not too difficult to express: for i in range(0, 10, 2): ## ... Do something with self.row[i] In contrast, doing the same thing without using an explicit container representation means that doing container-wide actions is harder to do. This is the code smell that we saw at the beginning of this post, where we see repetitive code. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Python script
Good morning Sir, merry Xmas. I have a question, please Sir if you do not mind. In this file E_vs_cutoff1.pdf, i represent the energy vs radial cutoff. And in the python script, i specified the limits of Y-axis as: pl.ylim(-5524.0,-5522.5). But as you can see the figure, there is -5522e-3 on left top and, the Energy values are between -2.0 and -0.5. It is as if the Energy values have been separated, despite the python instruction "pl.ylim(-5524.0,-5522.5)". So i was wondering, how can i fix it so that the figure shows indeed the Energy values from -5524.0 to -5522.5. How to set the Y-axis scale in that case? I hope you will understand my question. Thanks in advance and Merry Xmas again. Happy New year!!! ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python script
Mamy Rivo DIANZINGA writes: > Good morning Sir, merry Xmas. I have a question, please Sir if you do > not mind. Thank you for being so polite; we are usually quite informal here. > In this file E_vs_cutoff1.pdf, i represent the energy vs radial > cutoff. And in the python script, i specified the limits of Y-axis as: > pl.ylim(-5524.0,-5522.5). If you want to show us some Python code, you'll need to include it in the message. Please make sure to do the following to ensure your Python code is readable: * Make it *very* short, just enough to demonstrate the issue http://sscce.org/>. This means do not present your entire program, but only a small one you have contrived to focus on the issue. * Compose your messages in plain text, without special formatting http://email.about.com/od/netiquettetips/qt/When-In-Doubt-Send-Plain-Text-Email-Not-Fancy-Html.htm>. This will be much more likely to preserve the Python code as you actually wrote it, without modification in transit. If you do both of these you are much more likely to get a good response from this Tutor group. > Thanks in advance and Merry Xmas again. Happy New year!!! And to you, and to everyone here good cheer. -- \ “If consumers even know there's a DRM, what it is, and how it | `\ works, we've already failed.” —Peter Lee, Disney corporation, | _o__) 2005 | Ben Finney ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python script
On 2014-12-25 16:59, Ben Finney wrote: http://sscce.org/>. It may be that this link will go away. http://www.coderanch.com/t/628405/Ranch-Office/SSCCE-org-document-disappearing ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor