Problem with lists.

ssd cdsd at d.com
Fri Feb 20 11:12:00 EST 2009


Hi,

In the following code, (in Python 2.5)
I was expecting to get in "b" variable the values  b: [[0, 0], [0, 1],[0,
2], [0, 3],[0, 4], [1, 0],[1, 1], [1, 2], .....]
But I get only the last value [4,4], b: b: [[4, 4], [4, 4], [4, 4], ... ]

My code:

a = ["",""]
b = []

for i in range (0,5):
    for j in range (0,5):
        a[0] = i
        a[1] = j
        print "a: " + str(a)
        b.append(a)

print "b: " + str(b)

what is worng in the code?

Thanks,
Bye,








More information about the Python-list mailing list