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                  3-6
d                  15-20
e                  18-23

And here is what I need for an output:
part name   location
c.a.b            3-10
d.e               15-23

I've tried various methods, which all fail.  Does anyone have an idea
how to do this?

Thank you very much!
Jay
I haven't tried  but could you adapt this:-

data = [ 1,  4,5,6, 10, 15,16,17,18, 22, 25,26,27,28]
for k, g in groupby(enumerate(data), lambda (i,x):i-x):
    print map(itemgetter(1), g)

found here http://www.python.org/doc/2.6.2/library/itertools.html#module-itertools
--
Kindest regards.

Mark Lawrence.

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to