On Jan 31, 8:12 am, erikcw <[EMAIL PROTECTED]> wrote: > Hi, > > I have a list of numbers each with a +/- margin of error. I need to > identify which ones overlab each other. > > For example: > 55 +/- 3 > 20 +/- 2 > 17 +/- 4 > 60 +/- 3 > > #base, max, min > list = [ > (55, 58, 52), > (20, 22, 18), > (17, 21, 13), > (60, 63, 57), > ] > > In this example the range of list[0] overlaps the range of list[3] AND > list[1] overlaps list[2] > > What is the best way to in python to identify the list items that > overlap and the items that don't overlap with any other. >
One way would be to use sets and check for intersection: for idx, s in enumerate(mysets): for next_idx, next_s in enumerate(mysets[idx+1:]): if s.intersection(next_s): print "mylist[%d] and mylist[%d] intersect" % ( idx, idx + next_idx + 1 ) -- Hope this helps, Steve -- http://mail.python.org/mailman/listinfo/python-list