2
$\begingroup$

I have a long list (Table) consisting of "True"s and "False"s. I would like to identify the position in the list of the last entry that takes the value "False". Is there a way to do this?

$\endgroup$
3
  • 1
    $\begingroup$ Last[Position[list,False,1]][[1]]? $\endgroup$ Jul 23, 2019 at 0:38
  • 1
    $\begingroup$ Ironically, there is a command FirstPosition but no LastPosition. $\endgroup$ Jul 23, 2019 at 0:39
  • $\begingroup$ I am sure i saw a question very similar to this but can't find it. $\endgroup$
    – kglr
    Jul 23, 2019 at 0:49

1 Answer 1

4
$\begingroup$

You can use FirstPosition on Reversed input list:

Length[list] + 1 - FirstPosition[False] @ Reverse[list]

Alternatively, use PositionIndex:

Last @ PositionIndex[list][False]

or Position:

Last @ Position[False][list]

or SequenceCases:

SequenceCases[list, a:{___, False} :> Length[a]]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.