Let L be a list. Then if I do
for i in L:
if (bool):
L.remove(i)
sage is supposed to remove all such i's in L. But sage is not doing what I
expected:
sage: M
[['1', '1', '(', '(', ')'],
['1', '1', '(', ')', '('],
['1', '(', '1', '(', ')'],
['1', '(', '1', ')', '('],
['1', '(', '(', '1', ')'],
['1', '(', '(', ')', '1'],
['1', '(', ')', '1', '('],
['1', '(', ')', '(', '1'],
['1', ')', '(', '1', '('],
['(', '1', '1', '(', ')'],
['(', '1', '1', ')', '('],
['(', '1', '(', '1', ')'],
['(', '1', '(', ')', '1'],
['(', '1', ')', '1', '('],
['(', '1', ')', '(', '1'],
['(', '(', '1', '1', ')'],
['(', '(', '1', ')', '1'],
['(', '(', ')', '1', '1'],
['(', ')', '1', '1', '('],
['(', ')', '1', '(', '1'],
['(', ')', '(', '1', '1'],
[')', '1', '(', '1', '('],
[')', '(', '1', '1', '('],
[')', '(', '(', '1', '1']]
sage: len(M)
24
sage: for i in M:
if theNthX(i,'(',1)>theNthX(i,')',1):
M.remove(i)
....:
sage: len(M)
21
sage: for i in M:
if theNthX(i,'(',1)>theNthX(i,')',1):
M.remove(i)
....:
sage: len(M)
20
sage: for i in M:
if theNthX(i,'(',1)>theNthX(i,')',1):
M.remove(i)
....:
sage: len(M)
20
As you can see, sage is not only removing some i's such that
theNthX(i,'(',1)>theNthX(i,')',1) at a time rather than removing all such
i's at once. Can you tell me what's wrong?
Note: method `theNthX(s,n,t)` returns the position of the ``n``-th
substring ``t`` in ``s``. For example:
sage: s = ['(',')','1','1','(',')','(',')']
sage: theNthX(s,'(',1)
0
sage: theNthX(s,'(',3)
6
--
You received this message because you are subscribed to the Google Groups
"sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/groups/opt_out.