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}}
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}}
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}} *)
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]]
Drop[list, 0, -1].0can also beNone– Coolwater Jul 05 '18 at 16:06