expr.args gives a python tuple of the arguments that can be iterated
through in the normal ways.
for i in (1, 42, 'this'):
... print i
...
1
42
this
expr = 1+x+42/x
for i in expr.args:
... print i
...
1
42/x
x
for i, a in enumerate(expr.args):
... print i, a
...
0 1
1 42/x
2 x
What do you want to do in the loop?
Thanks, Chris; this is greatly appreciated. What I would like to do in
the loop is locate the indexed element. For example, if
expr = 0.5*p(1, 3)**(1 + n)/(deltax**2*deltay**2)
There are two things that I would like to do:
(1) Loop through the expression and find the position of the indexed
element p(1,3)**(1+n). I suppose that I could do this using Python's
isinstance() function, which would allow me to test if the object is an
indexed element, and store the index in a variable (let's call the
variable m).
(2) Use expr.coeff( expr.args[m] ) to obtain the coefficient
I believe that this would allow me to identify both the coefficient
0.5/(deltax**2*deltay**2) and the indexed element p(1, 3)**(1 + n)
without knowing that p(1, 3)**(1 + n) is the indexed element.
Nicholas
--
You received this message because you are subscribed to the Google Groups
"sympy" group.
To post to this group, send email to sy...@googlegroups.com.
To unsubscribe from this group, send email to
sympy+unsubscr...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/sympy?hl=en.