so, basically I have a list of sublists of varying length. For example,


And I would like to end up with


So, what I would like to filter out is all the sublist containing any string. Now, instead of filtering for any sublist containing any string, I also know that each sublist that I want to filter out has the "#" character as its first sublist element.

This is then the repeating pattern, a "#" character as the first element of every sublist of arbitrary length, that contains a string somewhere, and therefore should be removed from the main list.

How should I go about achieving this? I have tried a number of things with DeleteCases and StringMatchQ but couldn't really get the syntax right. Thank you very much in advance!


1 Answer 1

Cases[{__Integer}] @ list

{{1, 2}, {2, 3}, {3, 4}, {4, 5}}

DeleteCases[{"#",___}] @ list

{{1, 2}, {2, 3}, {3, 4}, {4, 5}}

DeleteCases[{"#", ___}|{___,_Symbol,___}] @ list

{{1, 2}, {2, 3}, {3, 4}, {4, 5}}

Cases[Except[{"#" ,___}|{___,_Symbol,___}]] @ list

{{1, 2}, {2, 3}, {3, 4}, {4, 5}}

  • $\begingroup$ Thank you! This works! The only part I need to change is put "#" instead of just # since the characters in the lists are apparently "#". $\endgroup$ Oct 16, 2019 at 17:02

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.