Removing last element of each sublist [duplicate]

If I have the following list:

{{1, 4}, {1, 3, 8}, {7, 12}, {2, 4, 9, 12}, {5, 7, 18, 19, 22}, {3, 5}}


How can I obtain a list in which each last element of the sublists is removed:

{{1}, {1, 3}, {7}, {2, 4, 9}, {5, 7, 18, 19}, {3}}

• Try Drop[list, 0, -1]. 0 can also be None Commented Jul 5, 2018 at 16:06

Most

You are after Most, Mapped over the list. Notice that f/@l is just a short form for Map[f,l].

Most /@ {{1, 4}, {1, 3, 8}, {7, 12}, {2, 4, 9, 12}, {5, 7, 18,
19, 22}, {3, 5}}
(* {{1}, {1, 3}, {7}, {2, 4, 9}, {5, 7, 18, 19}, {3}} *)


Part

You can use also Part ([[ ]]).

Part[
{{1, 4}, {1, 3, 8}, {7, 12}, {2, 4, 9, 12}, {5, 7, 18, 19, 22}, {3,
5}}
, All
, 1 ;; -2
]


or

{{1, 4}, {1, 3, 8}, {7, 12}, {2, 4, 9, 12}, {5, 7, 18, 19, 22}, {3,
5}}[[All, 1 ;; -2]]

• Thank you for the solutions.
– lio
Commented Jul 5, 2018 at 15:58
• What is the justification for voting to close this question and then, in effect, posting a duplicate as an answer? Commented Jul 5, 2018 at 20:12
• @tomd I didn't vote that it was a duplicate, I voted that it was "easily found in the documentation". But you are correct, I was focused on giving the OP a quick answer, I should have searched for duplicates and I didn't. My wrong. Good thing that Anton Antonov, Bob Hanlon, MarcoB, and Mr.Wizard identified it correctly. Commented Jul 6, 2018 at 7:31