This question continues form Can Mathematica delete some of the 0's from a list?
This time I want to delete zeros before the first positive integer.
I have a list: {0,0,0,1,2,3,0,0,4,5}.
I want Mathematica to return: {1,2,3,0,0,4,5}.
From ciao's answer
dropper2 = With[{s = SparseArray[#, Automatic, 0]["NonzeroPositions"]}, If[s === {}, {}, #[[;; s[[-1, 1]]]]]] &;
Internal`DeleteTrailingZeros@{1, 2, 3, 0, 0, 4, 5, 0, 0, 0}
res0 = Internal`DeleteTrailingZeros@test;
returns the wanted results (which was deleting zeros after the integers).
But how can I modify this code into deleting first zeros?
{}button above the edit window. The edit window help button?is also useful for learning how to format your questions and answers. You may also find this this meta Q&A helpful – Michael E2 Jan 18 '16 at 04:12Reversebefore & after will do it. Might be better ways, though. – Michael E2 Jan 18 '16 at 04:13#[[First@FirstPosition[#, a_?Positive] ;;]] &@{0, 0, 0, 1, 2, 3, 0, 0, 4, 5}. Would this work in general? I think so, unless your list can have negative numbers. – march Jan 18 '16 at 05:02Drop[list, FirstPosition[list, _?(# != 0 &)][[1]] - 1]– Hubble07 Jan 18 '16 at 05:09