minima = [] length = len(numbers) if length >= 2: if numbers[0] < numbers[1]: minima.append(numbers.index(numbers[0])) if length > 3: for i in range(1, length-1): if numbers[i] < numbers[i-1] and numbers[i] < numbers[i+1]: minima.append(numbers.index(numbers[i]))
if numbers[length-1] < numbers[length-2]: minima.append(numbers.index(numbers[length-1])) return minima numbers = [2, 7, 45, 3, 6, 98, 12, 67, 8] FindLocalMinima(numbers)
minima = [] length = len(numbers) if length >= 2: if numbers[0] < numbers[1]: minima.append(numbers[0]) if length > 3: for i in range(1, length-1): if numbers[i] < numbers[i-1] and numbers[i] < numbers[i+1]: minima.append(numbers[i])
if numbers[length-1] < numbers[length-2]: minima.append(numbers[length- return minima rand_ary = rd.sample(range(1,2000000),1000000) print("million local minima:") print(FindLocalMinima(rand_ary))