Remove one nesting level from a list of lists

102 Views Asked by At

I have a list with entries like

e:=[[[1,2]],[[3,4]],[[5,6]]];

I want to remove double list brackets to get a list looking like

result:=[[1,2],[3,4],[5,6]];

How can I do this in GAP?

2

There are 2 best solutions below

0
On BEST ANSWER

A one-liner would be

gap> List(e,x->x[1]);
[ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ]

If you want to modify the list in place, do

gap> for i in [1..Length(e)] do
> e[i]:=e[i][1];
> od;
gap> e;
[ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ]
1
On

k:=[];

for i in [1..length(e)] do

Add(k,e[i][1]);

od;

k;

this code worked. Thanks.