Create symbols() from a list of variables

294 views
Skip to first unread message

theoracle

unread,
Apr 4, 2016, 9:22:55 PM4/4/16
to sympy
Hello,

I have searched through the sympy docs and can't seem to find the answer to this.

Can I use lists to declare symbols for sympy.

example:

variables = ['x', 'y', 'z']

for i in range (0,len(variables))
     variables[i] = symbols(variables[i])

Aaron Meurer

unread,
Apr 4, 2016, 9:24:22 PM4/4/16
to sy...@googlegroups.com
You can just use symbols(variables) (symbols() works with a list of strings).

Aaron Meurer
> --
> You received this message because you are subscribed to the Google Groups
> "sympy" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to sympy+un...@googlegroups.com.
> To post to this group, send email to sy...@googlegroups.com.
> Visit this group at https://groups.google.com/group/sympy.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sympy/33baa071-7ea8-42e8-bd52-10ee10d28cb7%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Amit Saha

unread,
Apr 4, 2016, 10:02:36 PM4/4/16
to sy...@googlegroups.com
On Tue, Apr 5, 2016 at 11:24 AM, Aaron Meurer <asme...@gmail.com> wrote:
> You can just use symbols(variables) (symbols() works with a list of strings).

Or, for some reason if you want to:

variables = ['x', 'y', 'z']
sympy_variables = []
for v in variables:
sympy_variables[i] = Symbol(v)


The above can be further written concisely as:
sympy_variables = [Symbol(v) for v in variables]

so, sympy_variables will be a list of SymPy symbols in both cases.
> To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/CAKgW%3D6LzY6Q9xf2LozpxsreSqNg1dDk2V5U9zYy7_YjyQpE%3D9A%40mail.gmail.com.
> For more options, visit https://groups.google.com/d/optout.



--
http://echorand.me

theoracle

unread,
Apr 5, 2016, 5:51:46 PM4/5/16
to sympy
Thanks for the quick response that was good to hear, I am just getting started with Python for scientific computing and I am amazed at how powerful it is.
Reply all
Reply to author
Forward
0 new messages