# [Tutor] Lists in List question

Phillip Hart phillip.hart at gmail.com
Fri Jun 24 00:15:59 CEST 2005

```Hello,
I've been using lists within lists for several functions, but have been
unable, in loop form, to extract data from them or, in loop for, apply data
to them.

Basically, when extracting data, it only runs 1 loop. Likewise, when
initially assigning the data, it only runs 1 loop.

In the following example, the loop works once for x, and then a full loop (8
times) for y:

###
rr1=[0,0,0,0,0,0,0,0]
rr2=[0,0,0,0,0,0,0,0]
rr3=[0,0,0,0,0,0,0,0]
rr4=[0,0,0,0,0,0,0,0]
rr5=[0,0,0,0,0,0,0,0]
rr6=[0,0,0,0,0,0,0,0]
rr7=[0,0,0,0,0,0,0,0]
rr8=[0,0,0,0,0,0,0,0]
results=[rr1,rr2,rr3,rr4,rr5,rr6,rr7,rr8]

x=0
y=0
while x<8:
while y<8:
value=x+y
results[x][y]=value
y=y+1
x=x+1

x=0
y=0
while x<8:
while y<8:
print "(",x,", ",y,") is ",results[x][y] ###results[] is a list of lists
y=y+1
x=x+1

###

The output is simply:
( 0 , 0 ) is 0
( 0 , 1 ) is 1
( 0 , 2 ) is 2
( 0 , 3 ) is 3
( 0 , 4 ) is 4
( 0 , 5 ) is 5
( 0 , 6 ) is 6
( 0 , 7 ) is 7

Thanks for the help. I'm sure this is another newbie mistake, but one I'd be
greateful to see past.

-Phil
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20050623/35de4518/attachment.htm
```