I have data stored in a list of Associations. I would like to extract the values only for multiple keys. I was hoping to do it the same way list[[All,{1,2}]] can be used. But when I use this syntax with Associations I extract Key-value pairs instead of values. Is their a terse syntax for what I want?
assoc = { <|"a" -> 1, "b" -> 2, "c" -> 3|>, <|"a" -> 4, "b" -> 5, "c" -> 6|>, <|"a" -> 7, "b" -> 8, "c" -> 9|> }; assoc[[All, "a"]] (* {1,4,7} *) assoc[[All, {"a", "b"}]] {<|"a" -> 1, "b" -> 2|>, <|"a" -> 4, "b" -> 5|>, <|"a" -> 7, "b" -> 8|>}
Is their a terse syntax for what I want?I do not know. I do not use associations much. But you could always use mapping I suppose:assoc[[All, #]] & /@ {"a", "b"}$\endgroup$Lookup[{"a", "b"}] @ assoc$\endgroup$Lookup[]can thread across a list of associations! $\endgroup$