I have a list that looks like:


How would I create a list that looks like:


I have tried Flatten but that doesn't seem to work at the desired level.

  • 1
    $\begingroup$ Try mapping Flatten $\endgroup$ – M.R. Jun 2 at 3:39
  • $\begingroup$ Yeah that's exactly what i was missing, thanks! $\endgroup$ – D'Angelo Jun 2 at 3:43

You can tell Flatten to leave level 1 as-is but to flatten levels 2 and 3 together:

Flatten[z, {{1}, {2, 3}}]
(* {{a, b, b, c, c, d, d, e}, {b, c, d, e, w, e}} *)

This syntax is quite flexible, see Flatten command: matrix as second argument.

| improve this answer | |

Try the map function

list = {{{a, b}, {b, c}, {c, d}, {d, e}}, {{b, c}, {d, e}, {w, e}}}
Flatten /@ list
| improve this answer | |
  • $\begingroup$ Yes that was it, thank you. $\endgroup$ – D'Angelo Jun 2 at 3:43

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.