Note that there are some explanatory texts on larger screens.

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

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload