Dynamic variable name in custom function

Options

Hi,

I could not figure out how to do this or if it is even possible.

What I need:

  • Ability to name a variable based on the input in a custom function, so I can reuse a function with multiple calls and return a new list of items.
  • The function goes through a loop and in the loop I want to be able to name the variable that is to be returned with a new name that I specify

So for example if I pass a list of items with this structure:

{ "name": "Name Goes here", "value": 1293} and I call the function with this as an input along with a string as var_name of "amount".
I want to return :{ "name": "Name Goes here", "amount": 1293}

The issue is that in the loop of items I use "item" and there does not seems to be something like eval("item." + input_var_name ).

is this somethign even possible? I can do it with a different structure but this would be nice

Thanks!

Comments