To synthesize what has been said in the comments to the question:
- Several options are available, some of them making use of relatively new features of Mathematica
- There isn't a strong consensus to decide if some solution is better style than the other
So in no particular order:
somelist /. 0->Nothing
Suggested by myself in the question
Works well, but
Nothing being a relatively new addition to the language this solution won't appear in older code
In addition, Henrik Schumacher strongly discourage to get into the habit of using this solution large numerical data. The reason is "
Nothing unpacks arrays." Henrik continues by saying, for large numerical data "usually the three-argument version of
Pick is the fastest because that allows you to use a packed array as the second argument (unfortunately, Boolean arrays cannot be packed)"
Removing matching items is actually the same thing a picking only non matching items.
However, due to the way pattern matching is implemented, using
Except can lead to surprising results. Here is a working solution:
Pick[somelist, somelist, Except[0, _Integer]]
Other possible uses of
Pick to remove items are:
Pick[somelist, #!= 0 & /@ somelist ]
Pick[somelist,UnequalTo /@ somelist ]
Pick[somelist,EqualTo /@ somelist , False]
Suggested by Michael E2
DeleteCases "is a common solution, as is its complementary function
Pick can be used, too, to filter a list"
Based on Michael's suggestions above, I would add:
Select[somelist, # != 0 &]