searching a list of lists as a two-dimensional array?
Basically I'm programming a board game and I have to use a list of lists to represent the board (a list of 8 lists with 8 elements each). I have to search the adjacent cells for existing pieces and I was wondering how I would go about doing this efficiently. Thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: searching a list of lists as a two-dimensional array?
Thanks for the help guys but I'm a newbie at this and from what I understand from the code, it looks like you guys are using a two dimensional array. I am not using a two dimensional array. Basically, it looks like this: [ [' ',' ',' ',' ',' ',' ',' ',' '], [' ',' ',' ',' ',' ',' ',' ',' '], [' ',' ',' ',' ',' ',' ',' ',' '], [' ',' ',' ',' ',' ',' ',' ',' '], [' ',' ',' ',' ',' ',' ',' ',' '], [' ',' ',' ',' ',' ',' ',' ',' '], [' ',' ',' ',' ',' ',' ',' ',' '], [' ',' ',' ',' ',' ',' ',' ',' '] ] above: a list of lists NOT a two-dimensional array -- http://mail.python.org/mailman/listinfo/python-list
Re: searching a list of lists as a two-dimensional array?
OK I just realized that a list of lists can be accessed in the same way a 2d array would be accessed. Thanks anyways guys. -- http://mail.python.org/mailman/listinfo/python-list
python not returning true
I have a function, generally described as so: def function(args): if condition: if condition2: function(args+1) elif condition3: print "text" return True else: return False which is used in: if function(args): print "ok" so here basically "text" will print out when condition3 is true but it will not print out "ok" when condition3 is true. When it's true it should print out borth "text" and "ok" -- http://mail.python.org/mailman/listinfo/python-list
Re: python not returning true
On Feb 13, 9:37 pm, "John Machin" <[EMAIL PROTECTED]> wrote: > On Feb 14, 4:15 pm, "agent-s" <[EMAIL PROTECTED]> wrote: > > > I have a function, generally described as so: > > > def function(args): > > if condition: > > if condition2: > > function(args+1) > > return None> elif condition3: > > print "text" > > return True > > else: > > return False > >else: >return None > > There are two cases, indicated above, where you don't explicitly do a > "return", so you fall off the end of the function, and Python returns > None. > > Then when the function's caller tests the returned value, None is > treated as logically false. > > > which is used in: > > > if function(args): > > print "ok" > > > so here basically "text" will print out when condition3 is true but it > > will not print out "ok" when condition3 is true. When it's true it > > should print out borth "text" and "ok" > > In the second last sentence, it is difficult to determine what you > think is expected behaviour and what you say is the actual behaviour. > In the last sentence, what does the first "it" refer to? > > If the knowledge about returning None doesn't help you, try some > standard(??) techniques like inserting print statements or debugger > break-points. > > HTH, > John Thanks! That was exactly what it was. I solved it by using "return function(args+1)" instead of simply "function(args+1)." btw Steven you are so witty I hope to one day pwn noobs on newsgroups too. -- http://mail.python.org/mailman/listinfo/python-list
Re: python not returning true
Wow. I didn't realize you guys took this so seriously. -- http://mail.python.org/mailman/listinfo/python-list
