From a7ea9da52b9eb4160e112568e3a358b71bfc6b9b Mon Sep 17 00:00:00 2001 From: Andrei Lapets Date: Wed, 8 Nov 2023 11:33:20 -0500 Subject: [PATCH] Merge dictionaries in a backwards-compatible way. --- src/tinynmc/tinynmc.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/tinynmc/tinynmc.py b/src/tinynmc/tinynmc.py index b5c0ee5..241843e 100644 --- a/src/tinynmc/tinynmc.py +++ b/src/tinynmc/tinynmc.py @@ -13,6 +13,12 @@ def _prod(iterable): return functools.reduce(operator.mul, iterable) +def _merge(d, d_): + d__ = {} + d__.update(d) + d__.update(d_) + return d__ + def _shares(s, modulus, quantity) -> list[mod]: ss = [] for _ in range(quantity - 1): @@ -108,8 +114,7 @@ def compute(self, signature, mfss): """ # Combine all submitted coordinate-particle pair dictionaries # into a single dictionary. - # pylint: disable=consider-using-generator - mfs = functools.reduce((lambda mfs, mfs_: mfs | mfs_), mfss) + mfs = functools.reduce(_merge, mfss) # Compute this node's share of the overall sum of products. return sum([