# How do I flatten sublists while maintaining a separation between preexisting sublists?

I have a list that looks like:

z={{{a,b},{b,c},{c,d},{d,e}},{{b,c},{d,e},{w,e}}}


How would I create a list that looks like:

zz={{a,b,b,c,c,d,d,e},{b,c,d,e,w,e}}


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

• Try mapping Flatten – M.R. Jun 2 at 3:39
• Yeah that's exactly what i was missing, thanks! – 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.

Try the map function

list = {{{a, b}, {b, c}, {c, d}, {d, e}}, {{b, c}, {d, e}, {w, e}}}
Flatten /@ list

• Yes that was it, thank you. – D'Angelo Jun 2 at 3:43