Nov-05-2018, 01:48 PM
Hello everybody,
I have a list of dictionaries i need to perform some actions on. Following the sample code:
The weird thing is that just after the self.Action method, the dictionaries keep the new field but they are no longer ordered in the list..
How is that possible?
Thanks
I have a list of dictionaries i need to perform some actions on. Following the sample code:
j = json.loads(value) #list of dict is unordered here self.Action(j) #list of dict is unordered hereIn "self.Action" i use the following code to order the list and to assign a new field to all dictionaries:
def Action(self, pattern) pattern = sorted(pattern, key=lambda k: k['order']) #list of dict is ordered here for p in pattern: p["new_val"] = p["order"]When i order the list in "self.Action" it actually works out, if i print the list of dictionaries i have the right order and i have the new field ["new_val"].
The weird thing is that just after the self.Action method, the dictionaries keep the new field but they are no longer ordered in the list..
How is that possible?
Thanks