this is simple...
ToshiBoy
ToshiBoy at gmail.com
Sat Jun 28 00:30:25 EDT 2008
I am a newbie... and the first to admit it... but this has me stuffed:
I have two lists A and B that are both defined as range(1,27) I want
to find the entries that are valid for A = BxB
so here is my code:
A = range(1,27)
B = range(1,27)
for b in B:
if b*b in A:
print b
else:
B.remove(b)
I get, as expected 1,4,9,16,25 printed out being the only members of B
where the condition is true, but when I print B I get:
[1, 2, 3, 4, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25]
1 to 5 is correct, but why doesn't the remove method remove 7 and
above? What am I doing wrong here?
More information about the Python-list
mailing list