3

I want to delete the first element of a list of a list in Mathematica. For example I have:

x= {{{1,2},{4,5,6},{7,8,9}},{{10,11},{13,14,15},{16,17,18}}}

I want the answer like this:

{{{4,5,6},{7,8,9}},{{13,14,15},{16,17,18}}}

How can I do that??

Thanks

Kuba
  • 136,707
  • 13
  • 279
  • 740
Magdalena
  • 51
  • 1

5 Answers5

8

One way would be to evaluate

Map[Rest, x, 1]

which returns

{{{4, 5, 6}, {7, 8, 9}}, {{13, 14, 15}, {16, 17, 18}}}

Similarly,

Drop[x, None, 1]

returns the same output.


edit: The second way is probably the faster of the two

user42582
  • 4,195
  • 1
  • 10
  • 31
6
x[[All, 2 ;;]] (* or x[[;; , 2 ;;]] *)

{{{4, 5, 6}, {7, 8, 9}}, {{13, 14, 15}, {16, 17, 18}}}

Also:

☺ = {##2} & @@@ # &;
☺ @ x
> {{{4, 5, 6}, {7, 8, 9}}, {{13, 14, 15}, {16, 17, 18}}}
kglr
  • 394,356
  • 18
  • 477
  • 896
3
 Cases[x, {{__}, {a__}, {b__}} :> {{a}, {b}}]

Mathematica graphics

Nasser
  • 143,286
  • 11
  • 154
  • 359
3

In addition to the previous answers you can use the function Delete

Delete[{{{1, 2}, {4, 5, 6}, {7, 8, 9}}, {{10, 11}, {13, 14, 15}, {16, 
    17, 18}}}, {{1, 1}, {2, 1}}]

The resulting

{{{4, 5, 6}, {7, 8, 9}}, {{13, 14, 15}, {16, 17, 18}}}

Emad kareem
  • 864
  • 1
  • 5
  • 13
3
x = {{{1, 2}, {4, 5, 6}, {7, 8, 9}}, {{10, 11}, {13, 14, 15}, {16, 17, 18}}};

y = x;
y[[All, 1]] = Nothing;
(*or*)
y2 = Drop[x, 0, 1];

y === y2
True
Coolwater
  • 20,257
  • 3
  • 35
  • 64