I am using a set of Json objects to create set of dictionaries like this.
t = [{"A":100}, {"B":200}, {"C":300}]
Now I want them to cast in to a bigger dictionay in such a way that items no specified should take a default value.
default = {
"A" : 10,
"B" : 20,
"C" : 30
}
What I have tried so far is to use a class as follows
class MyClass:
default = {
"A" : 10,
"B" : 20,
"C" : 30
}
def __init__(self, input):
self.default.update(input)
def get(self):
return self.default
But when i try to create a list of dictionaries like this, it gives wrong answer.
a = [MyClass(x).get() for x in t]
[{'A': 100, 'C': 300, 'B': 200}, {'A': 100, 'C': 300, 'B': 200}, {'A': 100, 'C': 300, 'B': 200}]
seems to me like only one class instance was generated and the init was called upon it instead of creating many instances. Can you please point out the error/suggest other ways of doing this ?
Thanks