Why does this return {0} which is incorrect? I understand that I can use the pattern StringQ but I want to use not a number here.
myList = {6, "x", 7, 8, "y", 1, 2, "z", 5};
FirstPosition[myList, _?(Not@NumberQ[#] &)]
As written in the documentation for FirstPosition
, by default, Heads
is set to True
. This means that the function also looks at the head of the expression, which is in your case List
, and since it is not a number, it satisfies your condition. Use the option Heads -> False
to get the desired output {2}
.
Composition
operator:FirstPosition[myList, _?(Not@*NumberQ), Heads -> False]
$\endgroup$