No, but we could write a function to do such a thing, and then, if you need it to be an instance method, you could subclass or encapsulate the list.
def separate(array,separator): results = [] a = array[:] i = 0 while i<=len(a)-len(separator): if a[i:i+len(separator)]==separator: results.append(a[:i]) a = a[i+len(separator):] i = 0 else: i+=1 results.append(a) return results
If you want this to work as an instance method, we could do the following to encapsulate the list:
class SplitableList: def __init__(self,ar): self.ary = ar def split(self,sep): return separate(self.ary,sep)
or we can make a list of subclasses as follows:
class SplitableList(list): def split(self,sep): return separate(self,sep) a = SplitableList([1,3,4,6,8,5,3,4,5,8,4,3]) b = a.split([3,4])
source share