Reset python iterator when I get value -
if got 10, 50, 100, 120, 140, 160, 100, 50 code:
mock_len = len(db) epsilon = 20 max_data = 0 in range(mock_len - 1): if db[i+1][0]-db[i][0] == 20: max_data = db[i+1] print max_data
will print 120,140,160, want print 1 value, in case 120, how reset 0 max_data var when value in order contue compare in loop.
let's 120, 120 max_data initial var, reset max_data 0 , continue comparing. have bigger list of data want 1 value when encounter 20 diff.
as said in comments, querstion unclear. below longshot attempt.
db = [10, 50, 100, 120, 140, 160, 100, 50] g = [db[i] i, _ in enumerate(db) if db[i]-db[i-1] == 20] print(g) # [120, 140, 160] :prints instances difference 20 print(g[0]) # 120 :prints first instance difference 20
you not need reset first instance of something. alternatively, if want first 1 , don't want find them can use while
loop. let write on own though.
Comments
Post a Comment