Steven, I ran this: import time, collections, itertools t = time.clock()
q,w,e,r,sch = [],[],[],[],0 h = collections.defaultdict(itertools.repeat(0).next) f = open("D:/m4000.txt","rt") for o in range(int(f.readline())): row = map(int, f.readline().split()) q.append(row[0]) w.append(row[1]) e.append(row[2]) r.append(row[3]) f.close() for x in q: for y in w: h[x+y] += 1 for x in e: for y in r: sch += h[-(x + y)] q,w,e,r,h = None,None,None,None,None print sch print time.clock() - t ========= and it almost froze my PC... === but it was faster than my code on input file with 1000 rows: ====== 2.00864607094s VS 3.14631077413s -- http://mail.python.org/mailman/listinfo/python-list