1

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?

Olexandr Konovalov
  • 7,002
  • 2
  • 34
  • 72
S786
  • 1,001

2 Answers2

2

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 ] ]
Olexandr Konovalov
  • 7,002
  • 2
  • 34
  • 72
0

k:=[];

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

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

od;

k;

this code worked. Thanks.

S786
  • 1,001