I have a list in Mathematica with several items like <<199>> and <<104>>, I would like to get rid of them using DeleteCases
, but none of the patterns I have tried so far has worked.
1 Answer
Presumably you are dealing with something like this:
x1 = {1, 2, 3, 4, Range[0, 10, 1/3], 5, Sequence @@ Range[6, 99]};
x2 = Shallow[x1]
{1,2,3,4,{0,1/3,2/3,1,4/3,5/3,2,7/3,8/3,3,<<21>>},5,6,7,8,9,<<90>>}
You may not have an explicit Shallow
or Short
in your code; rather it may be applied automatically as part of a formatting function.
It is important to understand that this appearance of Skeleton
is typically only a matter of formatting; underlying that display form is a complete expression.
Perhaps you only want to see the entire expression (see InputForm
) but since you are seeking to use DeleteCases
I assume you wish to work with this display form itself. How you do that will depend on the origin of the expression. In my example above Shallow
does not actually change the expression; it remains as an invisible head that is not displayed in the output, but rather changes how the output is displayed. (This is similar to other formatting wrappers such as MatrixForm
.) To operate on the display form one must actually convert the expression into Box form, as explained here: Graphics in Notebook Different from Graphics Expression? Further, there appears to be a bug in parsing the Box form RowBox[{"\[LeftSkeleton]", "21", "\[RightSkeleton]"}]
therefore one cannot directly use ToExpression
which would simplify this operation. However one can still use patterns that operate on the Box form expression itself:
Replace[
ToBoxes[x2],
h_[x___, ",", RowBox[{"\[LeftSkeleton]", _, "\[RightSkeleton]"}]] :> h[x],
{0, -1}
] // ToExpression
{1, 2, 3, 4, {0, 1/3, 2/3, 1, 4/3, 5/3, 2, 7/3, 8/3, 3}, 5, 6, 7, 8, 9}
Another approach would be to mimic the behavior of Shallow
and circumvent it. For example:
Replace[
x1,
a_ /; Length[a] > 10 :> Take[a, 10],
{0, -1}
]
{1, 2, 3, 4, {0, 1/3, 2/3, 1, 4/3, 5/3, 2, 7/3, 8/3, 3}, 5, 6, 7, 8, 9}
I'll wait for a better description of the problem you actually face before taking this further.
_Skeleton -> Sequence[]
(related: mathematica.stackexchange.com/q/15188/5) $\endgroup$<<199>>
typically indicates that 199 items are not displayed in the output, however, those items are still part of the list. Are you certain that this is not the case in your application? $\endgroup$