Skip to content
Advertisement

How to optimise the grouping of values in lists by key in a dictionary list?

The script below works but I was wondering if there is a faster solution? With very large dictionary lists I noticed a small delay.

JavaScript

Advertisement

Answer

It seems keys in the dictionaries are the same, so you could use a dict comprehension:

JavaScript

Another pretty fast alternative is to use the cytoolz module.

JavaScript

Output:

JavaScript

Timings:

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement