Jun-05-2021, 02:45 PM
Hi everyone,
I need to compile a new list of new dictianories out of another list of dictianories. The new list should contain dictianories from the old one, reduced to pre determined keys if the match regarding another predetermined list of keys and values.
It can be assumed that all dictianories have exactly the same keys. The list cointains of thousands of individual dictianories.
What I have in mind is something like:
Thanks in advance
Markus
I need to compile a new list of new dictianories out of another list of dictianories. The new list should contain dictianories from the old one, reduced to pre determined keys if the match regarding another predetermined list of keys and values.
It can be assumed that all dictianories have exactly the same keys. The list cointains of thousands of individual dictianories.
What I have in mind is something like:
lod = [{"id": 1, "a": 1, "b": 2, "result": 9.82}, {"id": 2, "a": 1, "b": 2, "result": -5}, {"id": 3, "a": 1, "b": 5, "result": 7.98}] newList = selectionFunction(lod, ["a", "b"], [1, 2], ["id", "result"]) # Return should be: [{"id": 1, "result": 9.82}, {"id": 2, "result": -5}]How can I code this efficiently? I have a function but it takes forever.
Thanks in advance
Markus