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 hao.daniel
from itertools import groupby
def group_equal(Ite):
# your code here
newlist = []
for _, group in groupby(Ite):
newlist.append(list(group))
return newlist
if __name__ == '__main__':
print("Example:")
print(group_equal([1, 1, 4, 4, 4, "hello", "hello", 4]))
# These "asserts" are used for self-checking and not for an auto-testing
assert group_equal([1, 1, 4, 4, 4, "hello", "hello", 4]) == [[1,1],[4,4,4],["hello","hello"],[4]]
assert group_equal([1, 2, 3, 4]) == [[1], [2], [3], [4]]
assert group_equal([1]) == [[1]]
assert group_equal([]) == []
assert group_equal([99, 99, 9, 8, 8]) == [[99, 99], [9], [8, 8]]
print("Coding complete? Click 'Check' to earn cool rewards!")
June 13, 2019
Comments: