Wednesday, 11 September 2013

Python find coninuous interesctions of intervals

Python find coninuous interesctions of intervals

I tired multiple approaches, but failed to do this one job. All of them
use only 2 lists or range of lists. The one most promising was:
infile = open('file','r')
for line in infile:
line = line.split()
f = range(int(line[0]),int(line[1]))
results_union = set().union(*f)
print results_union
I have a file with start,end positions like this: (sorted)
1 5
1 3
1 2
2 4
3 6
9 11
9 16
12 17
I would like the output to be:
1 6
9 17

No comments:

Post a Comment