from collections import Counter
servers = [["tent"] * 3 + ["boots"] * 2, ["stove"] * 3 + ["boots"] * 2, ["lamp"] * 3 + ["boots"] * 2]
print("each server's best seller:", [Counter(s).most_common(1)[0] for s in servers])
print("best seller overall:", global_mode(servers))
each server's best seller: [('tent', 3), ('stove', 3), ('lamp', 3)]
best seller overall: boots
Boots sells 2 on every server, 6 in all, and tops none of them. So each server sends its whole count map, and the coordinator adds them. Decide ties out loud: Python's statistics.mode returns the first mode it finds in the data, which depends on the order the servers report in. A rule like the smallest value is safer across machines.
When there are too many distinct values for one machine, split the work by value instead. MapReduce partitions the keys into R pieces with a function like hash(key) mod R. Every count for a given product then lands on one owner.