2
$\begingroup$

I assume my question has been answered before, but I can't find such an answer anywhere:.

How can I drop the first element from each sublist within a list? I should be able to use

Map[Drop, list,2]

right? But how could I give Drop the arguments it needs from within Map?

$\endgroup$
4
  • 1
    $\begingroup$ You can simply use Rest instead: Rest /@ list $\endgroup$
    – Karsten7
    Commented Jul 14, 2016 at 20:02
  • $\begingroup$ Thanks - but for my future sanity: Can functions like Drop[] that require the list as their first argument even be used with Map[]? $\endgroup$
    – Nate
    Commented Jul 14, 2016 at 20:05
  • 1
    $\begingroup$ You could also use Drop[list, None, 1]. $\endgroup$
    – Karsten7
    Commented Jul 14, 2016 at 20:08
  • $\begingroup$ You can find a lot of examples on how to use functions with multiple arguments inside Map in the documentation for Map, the Pure Functions tutorial, and the Function (&) documentation. $\endgroup$
    – Karsten7
    Commented Jul 14, 2016 at 20:12

1 Answer 1

2
$\begingroup$

Prepare some data

data=Permutations[Range[3]]
(*{{1, 2, 3}, {1, 3, 2}, {2, 1, 3}, {2, 3, 1}, {3, 1, 2}, {3, 2, 1}}*)

Drop first element of each list

Map[Drop[#, 1] &, data]
(*{{2, 3}, {3, 2}, {1, 3}, {3, 1}, {1, 2}, {2, 1}}*)

Of course Rest as suggested by @Karsten is even shorter.

$\endgroup$
0

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