Skip to content

Commit

Permalink
Merge dictionaries in a backwards-compatible way.
Browse files Browse the repository at this point in the history
  • Loading branch information
lapets committed Nov 8, 2023
1 parent f89d53f commit a7ea9da
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/tinynmc/tinynmc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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([
Expand Down

0 comments on commit a7ea9da

Please sign in to comment.