I want to split a list into sublists using its sublist as a separator. The elements in the sublist must act like a starting point for list creation until the next element in the sublist comes up in the list.
It might be better to see it in an example:
lst = ['a','b','c','d','1','11','111','x','y','z']
sep = ['b','11','y']
This is my desired output:
[['b','c','d','1'],['11','111','x'],['y','z']]
So far, I have the following:
import itertools
[list(x[1]) for x in itertools.groupby(lst, lambda x: x in sep)]
But this spits out ['a'], ['b'], ['c', 'd', '1'], ['11'], ['111', 'x'], ['y'], ['z']] which is not what I want.
'a'in your desired output?lst?out = []; for x in lst: if x in sep: out.append(something) ...