[Tutor] indexing lists

Timothy Wilson wilson@visi.com
Mon, 5 Jun 2000 08:03:25 -0500 (CDT)


Hi everyone,

I'm wondering how, if even possible, you'd find the index of a given number
in the following list of lists:

l = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]

I've been playing around with my little tic tac toe program, and I can't
decide whether to use this list of lists structure for the matrix or a
simpler [1, 2, 3, 4, 5, 6, 7, 8, 9] structure.

I think programming the strategy might be easier with the more 2-dimensional
list of lists. But finding which moves are possible involves determining
which places in the list are occupied by integers, not "X" or "O". I need to
do l.index(spam) for that. Unfortunately, I can't do l.index(5). I can do
l.index([1, 2, 3]), however. Is it possible to get at that 2nd layer of
lists through an index statement?

-Tim

--
Tim Wilson      | Visit Sibley online:         | Check out:
Henry Sibley HS | http://www.isd197.k12.mn.us/ | http://www.zope.org/
W. St. Paul, MN |                              | http://slashdot.org/
wilson@visi.com |   <dtml-var pithy_quote>     | http://linux.com/