3
$\begingroup$

This question already has an answer here:

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

$\endgroup$

marked as duplicate by Kuba list-manipulation Dec 11 '17 at 15:03

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • $\begingroup$ If anyone disagrees with closing, please let me know. $\endgroup$ – Kuba Dec 11 '17 at 15:04
8
$\begingroup$

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

$\endgroup$
6
$\begingroup$
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}}}
$\endgroup$
3
$\begingroup$
 Cases[x, {{__}, {a__}, {b__}} :> {{a}, {b}}]

Mathematica graphics

$\endgroup$
3
$\begingroup$

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}}}

$\endgroup$
3
$\begingroup$
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
$\endgroup$

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