Is this a bug?

graham.matthews@maths.anu.edu.au
24 Jan 1995 00:02:14 GMT

The following program produces what I think is incorrect results.
The program is,

from time import clock
n = 100
m = 5
s1 = [ ["a"] * m ] * n
t = clock()
for i in range(n):
s1[i].append("a")
print len(s1), len(s1[1]), clock() - t

The output is,

100 105 0.08333

The 105 seems wrong to me (it should be 6, no?). Interestingly enough
if I now do the inverse transformation,

t = clock()
for i in range(n):
l = len(s1[i])
del s1[i][l-1:l]
print len(s1), len(s1[1]), clock() - t

I get the output,

100 5 0.099996

which would be the correct output if the first lot of output
were correct.

However if I do the inverse transformation as,

t = clock()
for i in range(n):
s1[i] = s1[i][0:len(s1[i])-1]
print len(s1), len(s1[1]), clock() - t

I get the output,

100 104 0.116662

Is this a bug or am I missing something?

graham

--
                      Je suis pour le communisme
                      Je suis pour le socialisme
                      Je suis pour le capitalisme
                     Parce que je suis opportuniste