split sequence into subsequences based on binary condition statusfn. a is a list, returns list of lists

def splitstatus(a,statusfn):
  'split sequence into subsequences based on binary condition statusfn. a is a list, returns list of lists'
  groups=[]; mode=None
  for elt,status in zip(a,map(statusfn,a)):
    assert isinstance(status,bool)
    if status!=mode: mode=status; group=[mode]; groups.append(group)
    group.append(elt)
  return groups