Questa versione non inserisce l'ultimo intervallo spurio da 0 eventi attivi:
s1ev = [(1723, 18550), (100000, 101000)]
s2ev = [(9154, 9307), (9340, 10442), (87361, 98214)]
starts = sorted(s[0] for s in s1ev + s2ev)
ends = sorted(s[1] for s in s1ev + s2ev)
actives = [[] for x in range(3)]
actives[0] = [[0, 0]]
actives_count = 0
while ends:
if starts and starts[0] < ends[0]:
x = starts.pop(0)
inc = 1
else:
x = ends.pop(0)
inc = -1
actives[actives_count][-1][1] = x
actives_count += inc
if ends:
actives[actives_count].append([x, 0])
--
http://thinkcode.tv - Prossimamente su questi schermi
http://beri.it - Blog di una testina di vitello
http://stacktrace.it - Aperiodico di resistenza informatica
_______________________________________________
Python mailing list
[email protected]
http://lists.python.it/mailman/listinfo/python