Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I have table:

t = {False, False, False, a <= 456, a <=567, a<= 897}

I want to delete all values which are 'False' and make my table to looks like:

t = {a <= 456, a <=567, a<= 897}

I was tried to make a commend like above:

For[i=1,i< Length[tt], i++, If[tt[[i]]==False, Delete[tt,i], Print[no]]]

But it didn't work. I don't want to delete each 'False' value separately, because I have many tables, and each has a different number of False values. How can I improve that?

share|improve this question

closed as off-topic by István Zachar, Mr.Wizard Jan 5 '14 at 21:01

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – István Zachar, Mr.Wizard
If this question can be reworded to fit the rules in the help center, please edit the question.

DeleteCases[t, False] –  Aky Jan 4 '14 at 18:02
In Mathematica, before starting to implement something, I find it best to first search to see if there is a command that might do what I want. Mathematica search is very good. If you type ?*Delete* for example, it will show you all commands with the word Delete in it. Then you could spot from the list, the ones that might do what you want and examine them more. This way, you would have found the DeleteCases easily yourself. screen shot !Mathematica graphics –  Nasser Jan 4 '14 at 18:29
@Nasser Ok, thanks, next time I will try to use your advice –  Ziva Jan 4 '14 at 18:31

2 Answers 2

up vote 1 down vote accepted
Cases[{False, False, False, a <= 456, a <= 567, a <= 897},  Except[False]]

Or more specifically

t = Cases[t, Except[False]]
share|improve this answer
Wow, so easy, and even without for loop. Thanks! –  Ziva Jan 4 '14 at 18:30
Loops are evil - and in Mathematica almost blasphemous ;) –  Ymareth Jan 5 '14 at 10:59

Another useful technique to remember is changing something to an empty sequence:

{False, False, False, a <= 456, a <= 567, a <= 897} /. False :> Sequence[]
share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.