Re: searching a list of lists as a two-dimensional array?

2007-02-14 Thread Gerard Flanagan
On Feb 12, 1:27 am, "agent-s" <[EMAIL PROTECTED]> wrote: > 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

Re: searching a list of lists as a two-dimensional array?

2007-02-13 Thread agent-s
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

Re: searching a list of lists as a two-dimensional array?

2007-02-13 Thread agent-s
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: [ [' ',' ',' ',' ',' ',' ',' ',' '], [' ',' ',' ',' ',' ',' ',' ',' '], [' ',

Re: searching a list of lists as a two-dimensional array?

2007-02-13 Thread Hendrik van Rooyen
"John Machin" <[EMAIL PROTECTED]> wrote: > On Feb 13, 4:57 pm, "Hendrik van Rooyen" <[EMAIL PROTECTED]> wrote: > > "John Machin" <[EMAIL PROTECTED]> wrote: > > > > > Now for the algorithm: all of that testing to see if you are about to > > > sail off the end of the world is a bit ugly and slow. Y

Re: searching a list of lists as a two-dimensional array?

2007-02-13 Thread John Machin
On Feb 13, 4:57 pm, "Hendrik van Rooyen" <[EMAIL PROTECTED]> wrote: > "John Machin" <[EMAIL PROTECTED]> wrote: > > > Now for the algorithm: all of that testing to see if you are about to > > sail off the end of the world is a bit ugly and slow. You can use bit- > > bashing, as Paul suggested, even

Re: searching a list of lists as a two-dimensional array?

2007-02-13 Thread Hendrik van Rooyen
"John Machin" <[EMAIL PROTECTED]> wrote: > Now for the algorithm: all of that testing to see if you are about to > sail off the end of the world is a bit ugly and slow. You can use bit- > bashing, as Paul suggested, even though it's on Steven D'Aprano's list > of 6 deadly sins :-) Thou shallt n

Re: searching a list of lists as a two-dimensional array?

2007-02-12 Thread Neil Cerutti
On 2007-02-12, James Stroud <[EMAIL PROTECTED]> wrote: > Paul Rubin wrote: >> "agent-s" <[EMAIL PROTECTED]> writes: >>>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

Re: searching a list of lists as a two-dimensional array?

2007-02-12 Thread Steven D'Aprano
On Sun, 11 Feb 2007 23:20:11 -0800, John Machin wrote: > Now for the algorithm: all of that testing to see if you are about to > sail off the end of the world is a bit ugly and slow. You can use bit- > bashing, as Paul suggested, even though it's on Steven D'Aprano's list > of 6 deadly sins :-) H

Re: searching a list of lists as a two-dimensional array?

2007-02-11 Thread John Machin
On Feb 12, 4:24 pm, Samuel Karl Peterson <[EMAIL PROTECTED]> wrote: > C-like way to do it, (warning, untested in python): > > for i in range(8): > for j in range(8): > for offset_i in range(-1,2): > for offset_j in range(-1, 2): > row = i + offset_i >

Re: searching a list of lists as a two-dimensional array?

2007-02-11 Thread bearophileHUGS
James Stroud: > import operator > srch = [(i,j) for i in [-1,0,1] for j in [-1,0,1] if (i,j) != (0,0)] > is_adj = reduce(operator.or_, [ary[row+i][col+j] for (i,j) in srch]]) Or maybe (untested), Python V.2.5: srch = [(i,j) for i in [-1,0,1] for j in [-1,0,1] if (i,j) != (0,0)] is_adj = any(ary[r

Re: searching a list of lists as a two-dimensional array?

2007-02-11 Thread James Stroud
Paul Rubin wrote: > "agent-s" <[EMAIL PROTECTED]> writes: > >>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 a

Re: searching a list of lists as a two-dimensional array?

2007-02-11 Thread Paul Rubin
"agent-s" <[EMAIL PROTECTED]> writes: > 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 efficie

Re: searching a list of lists as a two-dimensional array?

2007-02-11 Thread Gabriel Genellina
En Mon, 12 Feb 2007 02:24:54 -0300, Samuel Karl Peterson <[EMAIL PROTECTED]> escribió: > James Stroud <[EMAIL PROTECTED]> on Sun, 11 Feb 2007 16:53:16 -0800 > didst step forth and proclaim thus: > >> agent-s wrote: >> > Basically I'm programming a board game and I have to use a list of >> > list

Re: searching a list of lists as a two-dimensional array?

2007-02-11 Thread Samuel Karl Peterson
James Stroud <[EMAIL PROTECTED]> on Sun, 11 Feb 2007 16:53:16 -0800 didst step forth and proclaim thus: > agent-s wrote: > > 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 adjace

Re: searching a list of lists as a two-dimensional array?

2007-02-11 Thread James Stroud
agent-s wrote: > 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 > This i

searching a list of lists as a two-dimensional array?

2007-02-11 Thread agent-s
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/mailm