Re: [Tutor] Making Doubly Linked List with Less Lines of Code.

2015-01-02 Thread Alex Kleider
On 2015-01-02 13:57, Steven D'Aprano wrote: On Fri, Jan 02, 2015 at 09:57:29AM -0800, Alex Kleider wrote: On 2015-01-01 17:35, Alan Gauld wrote: >Repeats replicates the reference to the object but >does not create a new object. This part I can understand but, as Steven has pointed out, this be

Re: [Tutor] Making Doubly Linked List with Less Lines of Code.

2015-01-02 Thread Steven D'Aprano
On Fri, Jan 02, 2015 at 11:37:12AM -0500, WolfRage wrote: > On 01/02/2015 02:21 AM, Steven D'Aprano wrote: > >Your lookup_node method returns a GameTile or False on failure: > > > > def lookup_node(self, x, y, ): > > if not self.check_bounds(x, y): > > return False > >

Re: [Tutor] Making Doubly Linked List with Less Lines of Code.

2015-01-02 Thread Steven D'Aprano
On Fri, Jan 02, 2015 at 09:57:29AM -0800, Alex Kleider wrote: > On 2015-01-01 17:35, Alan Gauld wrote: > > >Repeats replicates the reference to the object but > >does not create a new object. > > This part I can understand but, as Steven has pointed out, > this behaviour changes if the object bei

Re: [Tutor] Making Doubly Linked List with Less Lines of Code.

2015-01-02 Thread Alan Gauld
On 02/01/15 19:03, WolfRage wrote: Tutors, on my next iteration I am going to add more of the game code. Since I am no longer using Doubly Linked Lists, should I create a new thread? Or should I continue with this thread to continue with the established context? Since you are now just looking f

Re: [Tutor] Making Doubly Linked List with Less Lines of Code.

2015-01-02 Thread Dave Angel
On 01/02/2015 10:43 AM, Steven D'Aprano wrote: On 03/01/15 02:14, WolfRage wrote: Dave or Steve, what mail program do you use? It appears Thunderbird is still posting the code all messed up. Which makes it impossible to communicate effectively with the list. One last test. I've removed python.

Re: [Tutor] Making Doubly Linked List with Less Lines of Code.

2015-01-02 Thread WolfRage
Tutors, on my next iteration I am going to add more of the game code. Since I am no longer using Doubly Linked Lists, should I create a new thread? Or should I continue with this thread to continue with the established context? ___ Tutor maillist -

Re: [Tutor] Making Doubly Linked List with Less Lines of Code.

2015-01-02 Thread WolfRage
On 01/02/2015 12:08 PM, Dave Angel wrote: class GameGrid(): def __init__(self, cols=8, rows=7, **kwargs): You probably want to reverse the order of the parameters; you've got almost everything else row-major You are right, a lot of inconsistency that will lead to errors latter on. I nee

Re: [Tutor] Making Doubly Linked List with Less Lines of Code.

2015-01-02 Thread Dave Angel
On 01/02/2015 12:57 PM, Alex Kleider wrote: On 2015-01-01 17:35, Alan Gauld wrote: Repeats replicates the reference to the object but does not create a new object. This part I can understand but, as Steven has pointed out, this behaviour changes if the object being repeated is immutable. Why

Re: [Tutor] Making Doubly Linked List with Less Lines of Code.

2015-01-02 Thread Alex Kleider
On 2015-01-01 17:35, Alan Gauld wrote: Repeats replicates the reference to the object but does not create a new object. This part I can understand but, as Steven has pointed out, this behaviour changes if the object being repeated is immutable. Why would one get a new object (rather than a new

Re: [Tutor] Making Doubly Linked List with Less Lines of Code.

2015-01-02 Thread Dave Angel
On 01/02/2015 11:37 AM, WolfRage wrote: On 01/02/2015 02:21 AM, Steven D'Aprano wrote: What is the purpose of the **kwargs? It doesn't get used, it just silently ignores them. Hopefully you got the answer for this from the previous message. Why does the GameTile record the coordinates as str

Re: [Tutor] Making Doubly Linked List with Less Lines of Code.

2015-01-02 Thread WolfRage
On 01/02/2015 02:21 AM, Steven D'Aprano wrote: What is the purpose of the **kwargs? It doesn't get used, it just silently ignores them. Hopefully you got the answer for this from the previous message. Why does the GameTile record the coordinates as strings? Hopefully you got the answer for

Re: [Tutor] Making Doubly Linked List with Less Lines of Code.

2015-01-02 Thread Dave Angel
On 01/02/2015 10:55 AM, Dave Angel wrote: On 01/02/2015 10:43 AM, Steven D'Aprano wrote: On 03/01/15 02:14, WolfRage wrote: Dave or Steve, what mail program do you use? It appears Thunderbird is still posting the code all messed up. Which makes it impossible to communicate effectively with the

Re: [Tutor] Making Doubly Linked List with Less Lines of Code.

2015-01-02 Thread Dave Angel
On 01/02/2015 10:53 AM, WolfRage wrote: On 01/02/2015 10:37 AM, Alan Gauld wrote: I use Thunderbird for posting too, and nobody has complained yet about my code layout. My account settings are: Composition&Addressing Compose in HTML - OFF Auto quote original then "START REPLY BELOW QUOTE" My

Re: [Tutor] Making Doubly Linked List with Less Lines of Code.

2015-01-02 Thread WolfRage
On 01/02/2015 10:37 AM, Alan Gauld wrote: I use Thunderbird for posting too, and nobody has complained yet about my code layout. My account settings are: Composition&Addressing Compose in HTML - OFF Auto quote original then "START REPLY BELOW QUOTE" My Tbird prefs are: Composition->General ta

Re: [Tutor] Making Doubly Linked List with Less Lines of Code.

2015-01-02 Thread Steven D'Aprano
On Sat, Jan 03, 2015 at 02:40:39AM +1100, Steven D'Aprano wrote: > On 03/01/15 02:14, WolfRage wrote: > >Dave or Steve, what mail program do you use? It appears Thunderbird is > >still posting the code all messed up. Which makes it impossible to > >communicate effectively with the list. > > Anot

Re: [Tutor] Making Doubly Linked List with Less Lines of Code.

2015-01-02 Thread Steven D'Aprano
On 03/01/15 02:14, WolfRage wrote: Dave or Steve, what mail program do you use? It appears Thunderbird is still posting the code all messed up. Which makes it impossible to communicate effectively with the list. One last test. I've removed python.org from the "Plain text only" domains, so th

Re: [Tutor] Making Doubly Linked List with Less Lines of Code.

2015-01-02 Thread Steven D'Aprano
On 03/01/15 02:14, WolfRage wrote: Dave or Steve, what mail program do you use? It appears Thunderbird is still posting the code all messed up. Which makes it impossible to communicate effectively with the list. Another test. This time I have re-enabled HTML posting for my account, but set T

Re: [Tutor] Making Doubly Linked List with Less Lines of Code.

2015-01-02 Thread Alan Gauld
On 02/01/15 14:49, WolfRage wrote: class GameTile(): def __init__(self, id, **kwargs): # id is (X,Y) self.id = id Still showing double spaced and without indent to me, on Thunderbird... I use Thunderbird for posting too, and nobody has complained yet about my code layout. My account sett

Re: [Tutor] Making Doubly Linked List with Less Lines of Code.

2015-01-02 Thread Steven D'Aprano
On 03/01/15 02:14, WolfRage wrote: Dave or Steve, what mail program do you use? It appears Thunderbird is still posting the code all messed up. Which makes it impossible to communicate effectively with the list. I normally use mutt, but for this post I've used Thunderbird. It is an old ve

Re: [Tutor] Making Doubly Linked List with Less Lines of Code.

2015-01-02 Thread WolfRage
Dave or Steve, what mail program do you use? It appears Thunderbird is still posting the code all messed up. Which makes it impossible to communicate effectively with the list. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscripti

Re: [Tutor] Making Doubly Linked List with Less Lines of Code.

2015-01-02 Thread WolfRage
On 01/02/2015 02:21 AM, Steven D'Aprano wrote: Fixing the mangled formatting, as best as I am able (and can be bothered). On Thu, Jan 01, 2015 at 11:48:18PM -0500, WolfRage wrote: class GameTile(): def __init__(self, id, **kwargs): # id is (X,Y) self.id = id What is the

Re: [Tutor] Making Doubly Linked List with Less Lines of Code.

2015-01-02 Thread WolfRage
import sys class GameTile(): def __init__(self, id, **kwargs): # id is (X,Y) self.id = id class GameGrid(): def __init__(self, **kwargs): self.cols = 8 self.rows = 8 # grid is 2d array as y, x ie [y][x]. self.grid = [[None] * self.rows for i in range(self.cols)] def make_grid(self)

Re: [Tutor] Making Doubly Linked List with Less Lines of Code.

2015-01-02 Thread WolfRage
On 01/02/2015 12:28 AM, Dave Angel wrote: On 01/01/2015 11:48 PM, WolfRage wrote: Final Code Using 2d List instead of Doubly Linked List. Please don't top-post. Instead, post your comments inline with the parts of the previous message to which you're responding. I did reply in-line, but i

Re: [Tutor] Making Doubly Linked List with Less Lines of Code.

2015-01-01 Thread Steven D'Aprano
Fixing the mangled formatting, as best as I am able (and can be bothered). On Thu, Jan 01, 2015 at 11:48:18PM -0500, WolfRage wrote: class GameTile(): def __init__(self, id, **kwargs): # id is (X,Y) self.id = id What is the purpose of the **kwargs? It doesn't get used, it ju

Re: [Tutor] Making Doubly Linked List with Less Lines of Code.

2015-01-01 Thread Steven D'Aprano
On Fri, Jan 02, 2015 at 12:28:38AM -0500, Dave Angel wrote: > On 01/01/2015 11:48 PM, WolfRage wrote: > >Final Code Using 2d List instead of Doubly Linked List. [...] > Is there a reason you doublespaced the whole thing? And why did you > retype it instead of just copy/pasting it? And why lose t

Re: [Tutor] Making Doubly Linked List with Less Lines of Code.

2015-01-01 Thread Dave Angel
On 01/01/2015 11:48 PM, WolfRage wrote: Final Code Using 2d List instead of Doubly Linked List. Please don't top-post. Instead, post your comments inline with the parts of the previous message to which you're responding. Is there a reason you doublespaced the whole thing? And why did you

Re: [Tutor] Making Doubly Linked List with Less Lines of Code.

2015-01-01 Thread WolfRage
Final Code Using 2d List instead of Doubly Linked List. class GameTile(): def __init__(self, id, **kwargs): # id is (X,Y) self.id = id class GameGrid(): def __init__(self, **kwargs): self.cols = 7 self.rows = 8 # grid is 2d array as y, x ie [y][x]. self.grid = [[None] * self.rows for i

Re: [Tutor] Making Doubly Linked List with Less Lines of Code.

2015-01-01 Thread Alan Gauld
On 02/01/15 01:35, Alan Gauld wrote: Repeats replicates the reference to the object but does not create a new object. reference = original # both refer to same object reference = original -> True Oops, typo, should be: reference == original -> True reference is original -> True -- Alan

Re: [Tutor] Making Doubly Linked List with Less Lines of Code.

2015-01-01 Thread Alan Gauld
On 02/01/15 01:03, Alex Kleider wrote: I don't think I understand the distinction between 'copies' and 'repeats'. copy creates a new object with the same attributes as the original original = [1,2,3] copy = original[:] # slicing creates a copy copy == original -> True copy is original -> F

Re: [Tutor] Making Doubly Linked List with Less Lines of Code.

2015-01-01 Thread Alex Kleider
On 2014-12-31 16:18, Steven D'Aprano wrote: py> grid[1][1] = 99 # Adjust a single cell. py> print(grid) [[0, 99, 0, 0, 0], [0, 99, 0, 0, 0], [0, 99, 0, 0, 0], [0, 99, 0, 0, 0]] while you expected: [[0, 0, 0, 0, 0], [0, 99, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]] Am I right? Yes, alt

Re: [Tutor] Making Doubly Linked List with Less Lines of Code.

2014-12-31 Thread Steven D'Aprano
On Tue, Dec 30, 2014 at 09:41:33PM -0800, Alex Kleider wrote: > In the process of doing so I discovered that list multiplication does > not at all behave the way I expected (as demonstrated by the > 'bad_flip_2_D' function.) Well, don't keep us in suspense. How did you expect it to behave, and

Re: [Tutor] Making Doubly Linked List with Less Lines of Code.

2014-12-31 Thread Steven D'Aprano
On Tue, Dec 30, 2014 at 05:40:04PM -0500, wolfrage8...@gmail.com wrote: > On Tue, Dec 30, 2014 at 2:37 PM, Danny Yoo wrote: > > If that's the case, then none of this requires linked list storage. > > > > Instead, we can represent this as a list of rows. Each row element > > would be itself a list

Re: [Tutor] Making Doubly Linked List with Less Lines of Code.

2014-12-30 Thread Alex Kleider
On 2014-12-30 14:40, wolfrage8...@gmail.com wrote: True, I could use a multidimensional list. And originally I was using I wanted the ability to quickly search across a row or up and down a column and so the added benefit of the linked list was that it simply requires me to access the next nod

Re: [Tutor] Making Doubly Linked List with Less Lines of Code.

2014-12-30 Thread wolfrage8...@gmail.com
On Tue, Dec 30, 2014 at 2:37 PM, Danny Yoo wrote: > If that's the case, then none of this requires linked list storage. > > Instead, we can represent this as a list of rows. Each row element > would be itself a list of tiles. In short, a matrix. See: > https://docs.python.org/2/faq/programming.

Re: [Tutor] Making Doubly Linked List with Less Lines of Code.

2014-12-30 Thread Danny Yoo
>> What are the _operations_ you want to support? Can you say more about >> this? > > I need to support lookups, no insertions or deletions are required. This > code will be used to quickly lookup nodes, and check for specific patterns > by checking the nodes values in either a row or column. As

Re: [Tutor] Making Doubly Linked List with Less Lines of Code.

2014-12-30 Thread WolfRage
This is my most recent rendition of the code. It still needs to be improved. Below I am answering some questions that were posed. Also I think my code is currently wrong because I think the print_by functions are both printing the list the same way. Tomorrow I will fix this and improve the code

Re: [Tutor] Making Doubly Linked List with Less Lines of Code.

2014-12-25 Thread WolfRage
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

Re: [Tutor] Making Doubly Linked List with Less Lines of Code.

2014-12-24 Thread Danny Yoo
> 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] Whoops. Apologies: I sh

Re: [Tutor] Making Doubly Linked List with Less Lines of Code.

2014-12-24 Thread Danny Yoo
On Wed, Dec 24, 2014 at 1:35 PM, WolfRage wrote: > I wrote some code recently to make a linked list of Nodes for a 2d graph, so > it consists of rows and columns. Now I wanted to make the code support being > doubly linked, forwards and backwards. What are the _operations_ you want to support? C

Re: [Tutor] Making Doubly Linked List with Less Lines of Code.

2014-12-24 Thread Danny Yoo
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 = N

Re: [Tutor] Making Doubly Linked List with Less Lines of Code.

2014-12-24 Thread WolfRage
Here is a condensed version of all of the applicable code but with out Linked List filled in, as I am preparing to re-write it. class GameTile(): def __init__(self, id, **kwargs): self.id = id class GameGrid(): def __init__(self, **kwargs): self.cols = 8 self.row

Re: [Tutor] Making Doubly Linked List with Less Lines of Code.

2014-12-24 Thread WolfRage
OK thanks for the rapid response, I will start rewriting the functions in this way now, and will come back with what I wind up with. Also Merry Christmas! On 12/24/2014 04:56 PM, Steven D'Aprano wrote: On Wed, Dec 24, 2014 at 04:35:06PM -0500, WolfRage wrote: I wrote some code recently to make

Re: [Tutor] Making Doubly Linked List with Less Lines of Code.

2014-12-24 Thread Steven D'Aprano
On Wed, Dec 24, 2014 at 04:35:06PM -0500, WolfRage wrote: > I wrote some code recently to make a linked list of Nodes for a 2d > graph, so it consists of rows and columns. Now I wanted to make the code > support being doubly linked, forwards and backwards. The difficult part > of this is that t

[Tutor] Making Doubly Linked List with Less Lines of Code.

2014-12-24 Thread WolfRage
I wrote some code recently to make a linked list of Nodes for a 2d graph, so it consists of rows and columns. Now I wanted to make the code support being doubly linked, forwards and backwards. The difficult part of this is that the links are per row and per column. But the code I think is over