Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
groupby directions solution in Clear category for Changing direction by Olpag
from itertools import groupby
def changing_direction(elements):
directions = [j - i > 0 for i, j in zip(elements, elements[1:]) if j - i != 0]
if directions:
return len(list(groupby(directions))) - 1
return 0
April 25, 2023
Comments: