Here's one solution. I'm using two lists, one for result, and one for joining together one-lengthed sub-lists. It's pretty self-explanatory
l = [[['the'], ['cool'], ['mani'], ['Party']], [','], ['has'], ['won'], [['the'], ['Delhi'], ['elections']], [','], ['with'], [['it']], ["'s"], [['leader'], ['Arv'], ['Kejjohn']], [['leading'], ['the', 'way']], ['.']]
res = [] # the final result
joined = [] # a temporary list for joining together elements
for sub_list in l:
if len(sub_list) == 1: #if there's only one element
joined.append(sub_list) # put it in joined
else:
if len(joined) > 0: #if joined has some sub_lists
res.append(joined) # append them to final result
joined = [] #empty joined
res.append(sub_list) #append the current sub_list and carry on
if len( l[-1] ) == 1: #this part accounts for edge-case of a one-lengthed last element.
res.append(l[-1])
pprint(res)
output:
[[['the'], ['cool'], ['mani'], ['Party']],
[['the'], ['Delhi'], ['elections']],
[[','], ['has'], ['won']],
[['leader'], ['Arv'], ['Kejjohn']],
[[','], ['with'], [['it']], ["'s"]],
[['leading'], ['the', 'way']],
[['.']]]