Domanda

How do you create a histogram sum of two dicts in erlang? Example if you have 2 dicts:

{a: 1, c: 4, d:7} and {a:5, b:8, d:1}

The sum would be:

{a:6, b:8, c:4, d:8}

Thanks

È stato utile?

Soluzione

Assume your dicts are bound to A and B variables respectevily, then:

Result = dict:merge(fun (_Key, V1, V2) -> V1 + V2 end, A, B)
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top