Python - Less than or Equal To Compare with two lists? -


new python, stupid question, have not been able figure 1 out after day of research , executing code.

i'd take 2 lists of integers (results , settings) , compare them in format:

(setting# - 0.1) <= result# <= (setting# +0.1) 

i need #'s in lists.

for example, if result1=4.6 , setting1=4.3, want compare 4.2 <= 4.6 <= 4.4 (which result in failure, far outside tolerance of 0.1. once compares that, want continue through list until finished, of course.

this not appear work have it. ideas?

results = [result1, result2, result3, result4, result5, result6] settings = [setting1, setting2, setting3, setting4, setting5, setting6] n in results , m in settings:     if (m-.1) <= n <= (m+.1): #compare values + or - 0.1 second error tolerance     print 'ok' else:     print 'fail' print 'done' 

you need use zip iterate on results , settings in tandem:

for n, m in zip(results, settings):     if m - 0.1 <= n <= m + 0.1:         print 'ok'     else:         print 'fail' print 'done'  

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

qt - Errors in generated MOC files for QT5 from cmake -