(Mathematica version: 8.0.4)
Given
lst = {{{{1, 2}, 3}, {{4, 5}, 6}}, {{{7, 8, 9, 10, 11}, 13}}};
lst2 = DeleteCases[lst, {x_, y_} /; y > 6, {2}]
gives
{{{{1, 2}, 3}, {{4, 5}, 6}}, {}}
Note the extra empty {}
at the end.
I could not find a way to remove it in the same command using DeleteCases
(which I think the right command to use for this), so I had to apply it again on the result
lst2 = DeleteCases[lst2, {}]
{{{{1, 2}, 3}, {{4, 5}, 6}}}
question: Is there a trick to do the above in one command without getting the empty {}
in the result? so that the command is self contained for all cases?
updatet 1
response to Lou suggestion below, of adding an extra { }
Here is an example where I get different results:
lst={{{{1, 2}, 3}, {{4, 5}, 6}}, {{{7, 8, 9, 10, 11}, 13}}}
now using the method of removing empty {}
by an extra application of DeleteCases
, we get
lst2 = DeleteCases[lst, {x_, y_} /; y >= 6, {2}]
{{{{1, 2}, 3}}, {}}
lst2 = DeleteCases[lst2, {}]
{{{{1, 2}, 3}}}
now using the method of extra { }
lst2 = DeleteCases[lst, {{x_, y_}} /; y >= 6]
{{{{1, 2}, 3}, {{4, 5}, 6}}}
which is the not the same, I should get only {{{{1, 2}, 3}}}
thanks