Re: Overlap in python

2009-08-06 Thread John Ladasky
On Aug 4, 3:21 pm, Jay Bird wrote: > Hi everyone, > > I wanted to thank you all for your help and *excellent* discussion.  I > was able to utilize and embed the script by Grigor Lingl in the 6th > post of this discussion to get my program to work very quickly (I had > to do about 20 comparisons pe

Re: Overlap in python

2009-08-06 Thread Marcus Wanner
On 8/5/2009 10:56 AM, nn wrote: On Aug 5, 7:13 am, Marcus Wanner wrote: On 8/4/2009 6:09 PM, MRAB wrote: >>> parts = [(5, 9, "a"), (7, 10, "b"), (3, 6, "c"), (15, 20, "d"), (18, 23, "e")] >>> parts.sort() >>> parts [(3, 6, 'c'), (5, 9, 'a'), (7, 10, 'b'), (15, 20, 'd'), (18, 23, 'e')] >>>

Re: Overlap in python

2009-08-05 Thread Mark Lawrence
Jay Bird wrote: Hi everyone, I wanted to thank you all for your help and *excellent* discussion. I was able to utilize and embed the script by Grigor Lingl in the 6th post of this discussion to get my program to work very quickly (I had to do about 20 comparisons per data bin, with over 40K bin

Re: Overlap in python

2009-08-05 Thread Scott David Daniels
Jay Bird wrote: Hi everyone, I've been trying to figure out a simple algorithm on how to combine a list of parts that have 1D locations that overlap into a non- overlapping list. For example, here would be my input: part name location a 5-9 b 7-10 c

Re: Overlap in python

2009-08-05 Thread nn
On Aug 5, 7:13 am, Marcus Wanner wrote: > On 8/4/2009 6:09 PM, MRAB wrote: > > >  >>> parts = [(5, 9, "a"), (7, 10, "b"), (3, 6, "c"), (15, 20, "d"), > > (18, 23, "e")] > >  >>> parts.sort() > >  >>> parts > > [(3, 6, 'c'), (5, 9, 'a'), (7, 10, 'b'), (15, 20, 'd'), (18, 23, 'e')] > >  >>> # Merge

Re: Overlap in python

2009-08-05 Thread Marcus Wanner
On 8/4/2009 6:09 PM, MRAB wrote: >>> parts = [(5, 9, "a"), (7, 10, "b"), (3, 6, "c"), (15, 20, "d"), (18, 23, "e")] >>> parts.sort() >>> parts [(3, 6, 'c'), (5, 9, 'a'), (7, 10, 'b'), (15, 20, 'd'), (18, 23, 'e')] >>> # Merge overlapping intervals. >>> pos = 1 >>> while pos < len(parts):

Re: Overlap in python

2009-08-05 Thread Bearophile
Albert van der Horst: >That is an algorithmic question and has little to do with Python.< Yes, but comp.lang.python isn't comp.lang.c, that kind of questions are perfectly fine here. They help keep this place from becoming boring. Bye, bearophile -- http://mail.python.org/mailman/listinfo/python

Re: Overlap in python

2009-08-05 Thread Albert van der Horst
In article , Jay Bird wrote: >Hi everyone, > >I've been trying to figure out a simple algorithm on how to combine a >list of parts that have 1D locations that overlap into a non- >overlapping list. For example, here would be my input: > >part name location >a 5-9 >b

Re: Overlap in python

2009-08-04 Thread Mensanator
On Aug 4, 2:57 pm, Gregor Lingl wrote: > Jay Bird schrieb: > > > > > > > Hi everyone, > > > I've been trying to figure out a simple algorithm on how to combine a > > list of parts that have 1D locations that overlap into a non- > > overlapping list.  For example, here would be my input: > > > part

Re: Overlap in python

2009-08-04 Thread Bearophile
kj: >     # connect the nodes >     for i in range(len(parts) - 1): >         part_i = parts[i] >         for j in range(i + 1, len(parts)): Note that's O(N^2), see the O(sort) standard solution by Mark Dickinson. Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: Overlap in python

2009-08-04 Thread kj
In <78d86d92-d373-4163-a418-600a3eb36...@o15g2000yqm.googlegroups.com> Mark Dickinson writes: >On Aug 4, 7:15=A0pm, Jay Bird wrote: >> Hi everyone, >> >> I've been trying to figure out a simple algorithm on how to combine a >> list of parts that have 1D locations that overlap into a non- >> ove

Re: Overlap in python

2009-08-04 Thread MRAB
Jay Bird wrote: Hi everyone, I've been trying to figure out a simple algorithm on how to combine a list of parts that have 1D locations that overlap into a non- overlapping list. For example, here would be my input: part name location a 5-9 b 7-10 c

Re: Overlap in python

2009-08-04 Thread kj
In Jay Bird writes: >Hi everyone, >I've been trying to figure out a simple algorithm on how to combine a >list of parts that have 1D locations that overlap into a non- >overlapping list. For example, here would be my input: >part name location >a 5-9 >b 7-

Re: Overlap in python

2009-08-04 Thread Mark Dickinson
On Aug 4, 9:03 pm, Mark Dickinson wrote: > for i, (pt, startend, name) in enumerate(transitions): Whoops. That line should just be: for pt, startend, name in transitions: The enumerate was accidentally left-over from a more complicated version. -- Mark -- http://mail.python.org/mailman/lis

Re: Overlap in python

2009-08-04 Thread Bearophile
Mark Dickinson: > # create sorted list of points where an interval is entered or left > transitions = [] > for name, (start, stop) in input: >     transitions.extend([(start, 'Start', name), (stop, 'Stop', name)]) > transitions.sort() > > # scan list, accumulating blocks along the way. Oh, right,

Re: Overlap in python

2009-08-04 Thread Gregor Lingl
Gregor Lingl schrieb: As my proposed solution shows this approach can be done with on board means of Python (namely the set type). This would be quite different though, if you had floating point boundaries of the intervals. ... or if the intgers involved were very big :-( Regards, Gregor

Re: Overlap in python

2009-08-04 Thread Gregor Lingl
DuaneKaufman schrieb: On Aug 4, 1:15 pm, Jay Bird wrote: ... For instance the interval module found at: http://members.cox.net/apoco/interval/ can be put to use: Given your data above: part name location a 5-9 b 7-10 c 3-6 from interval

Re: Overlap in python

2009-08-04 Thread Bearophile
Jay Bird: > I've been trying to figure out a simple algorithm on how to combine a > list of parts that have 1D locations that overlap into a non- > overlapping list. For example, here would be my input: > > part name location > a 5-9 > b 7-10 > c

Re: Overlap in python

2009-08-04 Thread DuaneKaufman
On Aug 4, 1:15 pm, Jay Bird wrote: > Hi everyone, > > I've been trying to figure out a simple algorithm on how to combine a > list of parts that have 1D locations that overlap into a non- > overlapping list.  For example, here would be my input: > > part name   location > a                  5-9 >

Re: Overlap in python

2009-08-04 Thread Mark Dickinson
On Aug 4, 7:15 pm, Jay Bird wrote: > Hi everyone, > > I've been trying to figure out a simple algorithm on how to combine a > list of parts that have 1D locations that overlap into a non- > overlapping list.  For example, here would be my input: > > part name   location > a                  5-9 >

Re: Overlap in python

2009-08-04 Thread Gregor Lingl
Jay Bird schrieb: Hi everyone, I've been trying to figure out a simple algorithm on how to combine a list of parts that have 1D locations that overlap into a non- overlapping list. For example, here would be my input: part name location a 5-9 b 7-10 c

Re: Overlap in python

2009-08-04 Thread Mark Lawrence
Jay Bird wrote: Hi everyone, I've been trying to figure out a simple algorithm on how to combine a list of parts that have 1D locations that overlap into a non- overlapping list. For example, here would be my input: part name location a 5-9 b 7-10 c

Re: Overlap in python

2009-08-04 Thread Marcus Wanner
On 8/4/2009 2:46 PM, Ann wrote: On Aug 4, 11:31 am, Marcus Wanner wrote: On Aug 4, 2:15 pm, Jay Bird wrote: Hi everyone, I've been trying to figure out a simple algorithm on how to combine a list of parts that have 1D locations that overlap into a non- overlapping list. For example, here

Re: Overlap in python

2009-08-04 Thread Ann
On Aug 4, 11:31 am, Marcus Wanner wrote: > On Aug 4, 2:15 pm, Jay Bird wrote: > > > > > Hi everyone, > > > I've been trying to figure out a simple algorithm on how to combine a > > list of parts that have 1D locations that overlap into a non- > > overlapping list.  For example, here would be my i

Re: Overlap in python

2009-08-04 Thread Marcus Wanner
On Aug 4, 2:15 pm, Jay Bird wrote: > Hi everyone, > > I've been trying to figure out a simple algorithm on how to combine a > list of parts that have 1D locations that overlap into a non- > overlapping list.  For example, here would be my input: > > part name   location > a                  5-9 >

Overlap in python

2009-08-04 Thread Jay Bird
Hi everyone, I've been trying to figure out a simple algorithm on how to combine a list of parts that have 1D locations that overlap into a non- overlapping list. For example, here would be my input: part name location a 5-9 b 7-10 c 3-6 d