How about simplifying the logic a bit: def compare(): for i in range(len(list1)): if list1[i] + list2[i] == 1: return 0 return 1 -- David Eppstein UC Irvine Dept. of Information & Computer Science eppstein at ics.uci.edu http://www.ics.uci.edu/~eppstein/