Cody Bable

Generation

generate functionThu, 29 Jun 2023

compare all the numbers in the list and return when there is a change in direction

def compare(a): b = [] for i in range(len(a) - 1): if a[i] > a[i + 1]: b.append(-1) elif a[i] < a[i + 1]: b.append(1) else: b.append(0) return b compare([1, 2, 3, 2, 1])

Questions about programming?Chat with your personal AI assistant