So, I think I have a good test and a better understanding of the problem: mylist = ['m', 's', 'b', 'x', 'y', 's', 'x', 'y', 's', 'EI'] sympy.var(mylist) test = m*s**2+b*x*y*s+x**2+y**2+s+EI args = list(test.args) args.sort(sympy.Basic._compare_pretty) args.reverse()
This doesn't get my list in the right order because of the number of variables or whatever _compare_pretty does. It seems like I need to make a dictionary or something that uses the powers of my main variable as the keys (this could cause issues if there is more than one arg with the same power). What is the best way to sort based on powers of the main variable? Is this the right approach: args[1].as_coeff_exponent('s') (returns (y**2, 0) in this case) stepping through args in a for loop. On Mon, Jun 1, 2009 at 5:52 PM, Ondrej Certik <ond...@certik.cz> wrote: > > On Mon, Jun 1, 2009 at 3:39 PM, Ryan Krauss <ryanli...@gmail.com> wrote: > > So, when would just adding an args.reverse() breakdown: > > > > den3 = s**4*m1*m2+k*s**2*m2+Gc*k > > args = list(den3.args) > > args.sort(sympy.Basic._compare_pretty) > > args.reverse() > > > > seems to produce the ordering that I want. Adding the reverse line to > > str.py and latex.py _print_Add methods seems to work. But obviously this > is > > a hack. > > yes, it's a hack, but otherwise that's the way. Now it should just > look for the main variable (as you suggested), that the user specifies > optionally, and sort it with respect to it. See > sympy/core/basic.py:Basic._compare_pretty for an example how to do > sort it. > > Ondrej > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sympy" group. To post to this group, send email to sympy@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 -~----------~----~----~----~------~----~------~--~---