Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to get only the raw values from python dictionary

I have a python dictionary dict = {'var0': x, 'var1': z}

type(x) = <class 'sympy.core.symbol.Symbol'>
type(z) = <class 'sympy.core.symbol.Symbol'>

I need the raw values to create a sympy function like this:

func = Function('g')(x,z) # with out '', x and y not string data type, its sympy symbols

Basically x,z in the above Function command has to come from the dictionary values. How can I achieve this?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

lets say dictionary has 3 items dict = {'var0': x, 'var1': z, 'var2': m} then the function command should build func = Function('g')(x,z,m)

>Solution :

If dictionary has keys in the same order as function then just unpack values of the dictionary:

mydict = {'var0': x, 'var1': z, 'var2': m}
Function('g')(*mydict.values())

this will be equivalent to Function('g')(x, z, m)

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading