Closed groutr closed 2 years ago
This approach also avoids calling factory() twice. It combines the ideas of itertoolz.groupby and cytoolz.merge_with.
itertoolz.groupby
cytoolz.merge_with
Best of all: there is a small performance gain:
In [2]: rand_d = [dict(zip(range(50), range(50))) for i in range(100)] In [12]: %timeit merge_with(max, rand_d) 527 µs ± 14.4 µs per loop (mean ± std. dev. of 7 runs, 1,000 loops each) In [13]: %timeit toolz.merge_with(max, rand_d) 730 µs ± 24.2 µs per loop (mean ± std. dev. of 7 runs, 1,000 loops each)
ping @eriknw
LGTM, thanks @groutr!
This approach also avoids calling factory() twice. It combines the ideas of
itertoolz.groupby
andcytoolz.merge_with
.Best of all: there is a small performance gain: