Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Group Equal consecutive by Oleg_Domokeev
from itertools import groupby
def group_equal(els):
return [list(g) for k, g in groupby(els)]
# one more variant without groupby
'''
from itertools import takewhile, dropwhile
def group_equal(els):
result = []
while els:
result.append(list(takewhile(lambda x: x == els[0], els)))
els = list(dropwhile(lambda x: x == els[0], els))
return result
'''
Dec. 20, 2018
Comments: