Consider
DeleteCases[{{1, 2, 3, 4}, {1, 3, 4, 5}}, {_, 3, __}]
{{1, 2, 3, 4}}
i.e., keep only those lists that don't have 3
on their second position. That works well.
Now,
DeleteCases[{{3, 5, 7, 5, 2}, {1, 2, 3, 4, 5}, {1, 3, 4, 5}}, {__, 3, __}]
{{3, 5, 7, 5, 2}}
gives only those lists that don't have 3
somewhere in the middle, i.e. on positions 2, 3 or 4 (or, in other words, keeps only those lists where 3
is in positions 1 or 5).
Question
How to make a general pattern/function that will keep only those lists (of arbitrary length n
) that don't have a given number a
on a specific position k
($1\leq k\leq n$)?