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 Rcp8jzd
def group_equal(els):
""" create and return a list whose elements are lists
that contain the consecutive runs of equal elements of the original list """
# If empty list
if not els:
return []
grouped = []
# index of the first element of consecutive elements
first = 0
for index, element in enumerate(els):
if els[first] != element:
grouped.append(els[first:index])
first = index
grouped.append(els[first:])
return grouped
Feb. 19, 2020