I have a list like below:-
list1 = ['box','ball','new','bat','chess','old']
I want to split this list based on values. In the above list, I want to insert the values before 'new' into a new list and the values before 'old' have to be inserted into a new list. The values before 'new' and 'old' can be one or more but here it has two values. I tried using split_after but I am getting the below result:-
from more_itertools import split_after
list1 = ['box','ball','new','bat','chess','old']
list(split_after(list1, lambda x: x == "new"))
Result:-
[['box', 'ball', 'new'], ['bat', 'chess', 'old']]
But desire output:-
result1 = ['box', 'ball']
result2 = ['bat', 'chess']