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?

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

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]]

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.