Skip to main content
added 109 characters in body
Source Link
Ali Hashmi
  • 9.1k
  • 4
  • 22
  • 43
list = {{a -> 1, b -> 2}, {a -> 3, b -> 4}};
Normal@GroupBy[Flatten@list, Keys -> Values, Total];
(* {a -> 4, b -> 6} *) 

Thread[Union @@ Keys[#] -> Apply[Plus, Values[#], {1}]]&@ Transpose[list]
(* {a -> 4, b -> 6} *)

as suggested by @J.M.

Normal@Merge[{{a -> 1, b -> 2}, {a -> 3, b -> 4}}, Total] (* applying Normal if you
want the answer with Head list *)
list = {{a -> 1, b -> 2}, {a -> 3, b -> 4}};
Normal@GroupBy[Flatten@list, Keys -> Values, Total];
(* {a -> 4, b -> 6} *)
list = {{a -> 1, b -> 2}, {a -> 3, b -> 4}};
Normal@GroupBy[Flatten@list, Keys -> Values, Total];
(* {a -> 4, b -> 6} *) 

Thread[Union @@ Keys[#] -> Apply[Plus, Values[#], {1}]]&@ Transpose[list]
(* {a -> 4, b -> 6} *)

as suggested by @J.M.

Normal@Merge[{{a -> 1, b -> 2}, {a -> 3, b -> 4}}, Total] (* applying Normal if you
want the answer with Head list *)
Source Link
Ali Hashmi
  • 9.1k
  • 4
  • 22
  • 43

list = {{a -> 1, b -> 2}, {a -> 3, b -> 4}};
Normal@GroupBy[Flatten@list, Keys -> Values, Total];
(* {a -> 4, b -> 6} *)