6
$\begingroup$

I like to delete the sublist that have the second element "" (or any other you can set as "-1" or "A")

In the next example, I would like to erase the first and third sublist. How can I do this with DeleteCases or a similar way?. Thinking in larger lists.

a = {
  {"A", "", 0, 23},
  {"B", "ber", 0, 23},
  {"C", "", 0, 23},
  {"D", "der", 0, 23},
  {"E", "eer", 0, 23}
  }
DeleteCases[a, a[[i, 2]] == ""]

====================== SOLVED in the comment of J.M.

$\endgroup$
3
  • 4
    $\begingroup$ DeleteCases[a, {_, "", __}]. $\endgroup$ Jul 26, 2016 at 15:18
  • $\begingroup$ @J.M. thank you, ok. The documentation is not much usefull for me. This forum is the best for learning. $\endgroup$
    – Mika Ike
    Jul 26, 2016 at 15:25
  • 6
    $\begingroup$ If you understood how that worked, consider writing an answer to your question. $\endgroup$ Jul 26, 2016 at 15:29

1 Answer 1

3
$\begingroup$

Use only Delete:

a = {{"A", "", 0, 23}, {"B", "ber", 0, 23}, {"C", "", 0, 23}, {"D", 
   "der", 0, 23}, {"E", "eer", 0, 23}}

$\left( \begin{array}{cccc} \text{A} & \text{} & 0 & 23 \\ \text{B} & \text{ber} & 0 & 23 \\ \text{C} & \text{} & 0 & 23 \\ \text{D} & \text{der} & 0 & 23 \\ \text{E} & \text{eer} & 0 & 23 \\ \end{array} \right)$

Delete[a, {{1}, {3}}]

$\left( \begin{array}{cccc} \text{B} & \text{ber} & 0 & 23 \\ \text{D} & \text{der} & 0 & 23 \\ \text{E} & \text{eer} & 0 & 23 \\ \end{array} \right)$

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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