2
$\begingroup$

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

list={{#,a,b,c,d},{#,e,f,g},{#,h,1},{#,2},{#},{#,k,l,m,n,o},{#,a,b,1,2},{1,2},{2,3},{3,4},{4,5}}

And I would like to end up with

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

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!

$\endgroup$
3
$\begingroup$
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}}

$\endgroup$
  • $\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$ – Jeff Bastian Oct 16 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.