2009/10/19 Marco Beri <marcob...@gmail.com>: > 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]) > >
E' perfetto, grazie mille. Il codice mi è un po' oscuro, quindi ora mi metto con l'interprete ad eseguire passo passo i tuoi statement e vedere come costruisci il tutto. Grazie! _______________________________________________ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python