Home > Back-end >  How to get only the raw values from python dictionary
How to get only the raw values from python dictionary

Time:01-08

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?

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)

CodePudding user response:

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)

  •  Tags:  
  • Related