How do i smartly join a List of Associations (eg. returned by ParallelTable) such that i get a single Association?

list = {<|"a" -> aValue|>, <|"b" -> bValue|>}
association = <|"a" -> aValue,"b" -> bValue|>

what line of code returns association created from list? I tried various stock functions, but failed to find a fitting one. It could work by calling Join[(*elements of list seperated by comma*)] but i do not know how to write such call.

My current workaround is:

assoc = <||>
Do[AppendTo[assoc, elem], {elem, list}]
  • 1
    $\begingroup$ Join@@{<|"a" -> aValue|>, <|"b" -> bValue|>} $\endgroup$ – Kirill Belov Oct 2 '18 at 14:36
  • 2
    $\begingroup$ Merge[{<|"a" -> 1|>, <|"b" -> 3|>}, Identity]? $\endgroup$ – J. M.'s ennui Oct 2 '18 at 14:46
  • 7
    $\begingroup$ And the winner is: <|list|> ;P $\endgroup$ – Kuba Oct 2 '18 at 15:53
  • 1
    $\begingroup$ @J.M.issomewhatokay Either that, or Merge[{<|"a" -> 1|>, <|"b" -> 3|>}, First], if you don't want lists in your result. $\endgroup$ – Sjoerd Smit Oct 2 '18 at 15:58

This is CW to record Kuba's comment which seems to be the simplest answer.

list = {<|"a" -> aValue|>, <|"b" -> bValue|>};
assoc = <|list|>
<|"a" -> aValue, "b" -> bValue|>

From the Details section of Association



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.