I am looking to search through my array [1,2,3,4,5] representing seconds and check whether my time variable 't' (intially 0) matches a range item, at which point I want to print that time 't' ONLY ONCE.
The loop will be read again but this time NOT print out anything unless another match is found - ie. t is now 2 seconds so when t = 2 then print 't' ONCE.
How can I achieve this in Python? This is what I currently have:
t = 0
dt = 0.05
a = np.arange(1,5,1)
while t < 10:
for x in range(a.size):
if int(t) == a[x,0]:
print "TIME IS NOW >>>>>>>", int(t)
t = t+dt
This is working except it is printing the previously matched number again and again until a new matched number is found:
TIME IS NOW >>>>>>>1
TIME IS NOW >>>>>>>1
TIME IS NOW >>>>>>>1
TIME IS NOW >>>>>>>1
TIME IS NOW >>>>>>>1
TIME IS NOW >>>>>>>1
TIME IS NOW >>>>>>>1
TIME IS NOW >>>>>>>1
TIME IS NOW >>>>>>>2
TIME IS NOW >>>>>>>2
and so on.....
I want a RESULT of:
TIME IS NOW >>>>>>>1
-
-(looping but no print out)
TIME IS NOW >>>>>>>2
-
and so on...