The easiest way is probably:
out = [[]]
for element in lst:
out[-1].append(element)
if predicate(element):
out.append([])
Note that this would leave an empty list at the end of out
, if predicate(element):
for the last element
. You can remove this by adding:
out = [l for l in out if l]