I have for example the following list:
[\'|\', u\'MOM\', u\'DAD\', \'|\', u\'GRAND\', \'|\', u\'MOM\', u\'MAX\', u\'JULES\', \'|\']
and wan
Simple solution using plain old for-loop (was beaten to it for the groupby solution, which BTW is better!)
seq = ['|', u'MOM', u'DAD', '|', u'GRAND', '|', u'MOM', u'MAX', u'JULES', '|']
S=[]
tmp=[]
for i in seq:
if i == '|':
S.append(tmp)
tmp = []
else:
tmp.append(i)
# Remove empty lists
while True:
try:
S.remove([])
except ValueError:
break
print S
Gives
[[u'MOM', u'DAD'], [u'GRAND'], [u'MOM', u'MAX', u'JULES']]