Answers for "create a dict from variables and give name"

0

create a dict from variables and give name

mydict = NewClass()
vars = ['a', 'b', 'c']
for v in vars: 
    setattr(mydict, v, eval(v)) 

mydict.__dict__
{'a': 9, 'b': ['hello', 'world'], 'c': (True, False)}
Posted by: Guest on May-13-2020

Code answers related to "create a dict from variables and give name"

Python Answers by Framework

Browse Popular Code Answers by Language