3
$\begingroup$

I am completely new to Mathematica.

I have an association in the form <| a -> {1,2,3,4},b -> {5,4,3,2},c -> {5,7,3,4} |>

I want my output to be of the form {{a,1,2,3,4},{b,5,4,3,2},{c,5,7,3,4}}

Can I do that? I have tried different things but could not figure out any thing.

$\endgroup$
5
$\begingroup$
asso = <| a -> {1, 2, 3, 4}, b -> {5, 4, 3, 2}, c -> {5, 7, 3, 4} |>;

KeyValueMap[Flatten[{##}] &] @ asso

 {{a, 1, 2, 3, 4}, {b, 5, 4, 3, 2}, {c, 5, 7, 3, 4}}

Also

Flatten /@ List @@@ Normal @ asso

 {{a, 1, 2, 3, 4}, {b, 5, 4, 3, 2}, {c, 5, 7, 3, 4}}

| improve this answer | |
$\endgroup$
2
$\begingroup$

You can combine matrices column-wise with Join[mat1, mat2, 2]

asso = <|a -> {1, 2, 3, 4}, b -> {5, 4, 3, 2}, c -> {5, 7, 3, 4}|>;
Join[Transpose[{Keys[asso]}], Values[asso], 2]

{{a, 1, 2, 3, 4}, {b, 5, 4, 3, 2}, {c, 5, 7, 3, 4}}

| improve this answer | |
$\endgroup$
2
$\begingroup$
KeyValueMap[Join[{#1}, #2] &, ass]

{{a, 1, 2, 3, 4}, {b, 5, 4, 3, 2}, {c, 5, 7, 3, 4}}

| improve this answer | |
$\endgroup$

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.