Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First_of_Group Equal consecutive solution in Speedy category for Group Equal consecutive by Oleg_Novikov
def group_equal(els):
if not els:
return []
res = []
tmp = []
for i, val in enumerate(els):
if i == 0 or val in tmp:
tmp.append(val)
else:
res.append(tmp)
tmp = []
tmp.append(val)
res.append(tmp)
return res
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([]) == []
print("Coding complete? Click 'Check' to earn cool rewards!")
May 29, 2019
Comments: