# How to delete sublist in a list (with DeleteCase or similar)?

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.

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

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)$

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


Using Cases:

Cases[a, {_, Except[""], ___}]

(*{{"B", "ber", 0, 23}, {"D", "der", 0, 23}, {"E", "eer", 0, 23}}*)


Or using Pick:

Pick[#, Map[#[[2]] =!= "" &, #]] &@a

(*{{"B", "ber", 0, 23}, {"D", "der", 0, 23}, {"E", "eer", 0, 23}}*)

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


Using SequenceSplit (new in 11.3)

Catenate @ SequenceSplit[a, {{_, "", __}}]


{{"B", "ber", 0, 23}, {"D", "der", 0, 23}, {"E", "eer", 0, 23}}

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

delpos = Position[a[[All, 2]], "A" | ""]

Delete[a, delpos]


or to add an Alternative to J.M.'s comment:

DeleteCases[a, {_, "" | "A", __}]


or

Select[a, FreeQ[#[[2]], "" | "A"] &]


{{"B", "ber", 0, 23}, {"D", "der", 0, 23}, {"E", "eer", 0, 23}}