Linked Questions

Popular Questions

Dynamically create variables inside function

Asked by At

I want to create variables inside function from dictionary.

Lets say I have a dictionary

bar = {'a': 1, 'b': 2, 'c': 3}

and function

def foo():
  pass

What I want to do is to create inside function "foo" variables with names of each dictionary item name and values as dictionary item values

So in the end it should be similar to

def foo():
  a = 1
  b = 2
  c = 3

Is it possible at all? And if it does, how to do such thing?

Related Questions