I have a while loop that runs through a fixed step and constantly checks if a value in an array is not equal to the while loop counter, and prints that number:
import numpy as np
values = [60.0, 75.8, 85.0, 90.0]
values = np.asarray(values)
counter = 50
while counter <= 100:
closest = (np.abs(values - counter)).argmin()
if (values[closest] > (counter - 1) and values[closest] <counter):
print("we skipped a value " + str(values[closest]))
counter = counter + 1
I wrote this code which has the mentioned functionality but it doesn't seem very elegant or efficient. Is there a quicker way to find these skipped values in Python?
counter > values[closest] > counter - 1, which is only satisfied for numbers that aren't integer values. If you don't want to skip a value, why don't you directly iterate on the values?