user3170122
user3170122

Reputation: 717

Passing 'key' dynamically in 'key=value' type parameter

I had this following rough code snippet.

param={'a':1,'b':2}
for k,v in param.items():
     func2(k=v)

func2 is defined as:

func2(**kwargs):
    print kwargs.get('a',None)
    print kwargs.get('b',None)

When func2() is called the variable 'k' is being passed instead of it's value.How to pass k's value to func2(**kwargs) ?

Upvotes: 1

Views: 76

Answers (1)

falsetru
falsetru

Reputation: 369244

Use ** operator:

for k, v in param.items():
     func2(**{k: v})

Upvotes: 1

Related Questions