2
$\begingroup$

Suppose I have the following list:

l={{{1},{2}},{{3}},{{4},{5}}};

How can I flatten this such that I get:

{{1,2},{3},{4,5}}

I tried Flatten[l, 1] but that gives:

{{1}, {2}, {3}, {4}, {5}}
$\endgroup$

2 Answers 2

2
$\begingroup$
Flatten[#, 1] & /@ l   

{{1, 2}, {3}, {4, 5}}

$\endgroup$
4
$\begingroup$
Flatten[l, {3, 1}]

{{1, 2}, {3}, {4, 5}}

Also

Flatten /@ l
Flatten[l, {{3, 1}}]
Join @@@ l

all give

{{1, 2}, {3}, {4, 5}}

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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