[go: up one dir, main page]

Items tagged with flatten

Feed App Center

Given a list with sublists e.g.

[[a,b],[[c,d,e]]]

is there a way of merging everything into a single list, for example

[a,b,c,d,e]

I can't final an equivalent to Mathematica's Flatten for sets. I know Maple has ListTools:-Flatten for lists.   

For example, given set r:={a,{b,c},d,{e,f,{g,h}}}; How to convert it to  {a,b,c,d,e,f,g,h}; 

does one have to convert each set and all the inner sets to lists, then apply ListTools:-Flatten to the result? How to map convert(z,list) for all levels?

     map(z->convert(z,list),r);

does not work, since it only maps at top level, giving {[a], [d], [b, c], [e, f, {g, h}]}

So doing

   ListTools:-Flatten(convert(map(z->convert(z,list),r),list));

Gives [a, d, b, c, e, f, {g, h}] 

 

     

Page 1 of 1