Internet [EMAIL PROTECTED] To python-list Sent by: cc python-list-bounces+matthew.warren=uk.bnpparibas.com@ python.org Subject Re: How to identify which numbers in a list are within each others' 31/01/2008 22:48 range
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. > Is this usable? Assuming you transform your 3 tuples into a list of start-end 2 tuples and sort them for lowest to highest, then lst=[(55,58,52),(20,22,18),(17,21,13),(60,63,57)] a=[ (l[2],l[1]) for l in lst ] a.sort() a=[(1,5),(4,9),(10,12),(11,15),(16,19)] i=[ (pair,a[a.index(pair)+1]) for pair in a[:-1] if a[a.index(pair)+1][0]<pair[1]] i [((13, 21), (18, 22)), ((52, 58), (57, 63))] ? Matt. This message and any attachments (the "message") is intended solely for the addressees and is confidential. If you receive this message in error, please delete it and immediately notify the sender. Any use not in accord with its purpose, any dissemination or disclosure, either whole or partial, is prohibited except formal approval. The internet can not guarantee the integrity of this message. BNP PARIBAS (and its subsidiaries) shall (will) not therefore be liable for the message if modified. Do not print this message unless it is necessary, consider the environment. --------------------------------------------- Ce message et toutes les pieces jointes (ci-apres le "message") sont etablis a l'intention exclusive de ses destinataires et sont confidentiels. Si vous recevez ce message par erreur, merci de le detruire et d'en avertir immediatement l'expediteur. Toute utilisation de ce message non conforme a sa destination, toute diffusion ou toute publication, totale ou partielle, est interdite, sauf autorisation expresse. L'internet ne permettant pas d'assurer l'integrite de ce message, BNP PARIBAS (et ses filiales) decline(nt) toute responsabilite au titre de ce message, dans l'hypothese ou il aurait ete modifie. N'imprimez ce message que si necessaire, pensez a l'environnement. -- http://mail.python.org/mailman/listinfo/python-list