Message Boards Message Boards

0
|
3113 Views
|
4 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Delete elements containing numeric entries from a list?

Posted 6 years ago

Hi, I have a large list of 1*2 lists that contain various dummy variables, something like

list = {{a, b + c}, {u, y - h}, {d, g + h}, {d, 0}, {v, 0}}

I want to remove every element that has zero as the second entry, I have tried Select, DeleteCases andCases but none worked because Mathematica tried to equate variables to zero

How can I do that?

Thanks

eftsrd

POSTED BY: eft rsd
4 Replies

I would try DeleteCases[list, {_, 0}].

POSTED BY: Gianluca Gorni

I would try DeleteCases[list, {_, 0}].

POSTED BY: Neil Singer
Posted 6 years ago

It worked! Thanks.

POSTED BY: eft rsd

My original post got corrupted and it repeated Gianluca's post.

I added to Gianluca's answer that there are many ways to do this and that your original attempts may have worked if you used === (SameQ) instead of ==. Mathematica does not know if g+h == 0 because g and h are not yet defined. However, Mathematica does know that g+h are not identical to 0. So if you are testing in Select, DeleteCases, Cases, etc. you usually need to use SameQ or UnSameQ and not Equals

Regards.

Neil

POSTED BY: Neil Singer
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract