1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
from interval import Interval, IntervalSet
# coding
r1 = IntervalSet([Interval(1, 1000), Interval(1100, 1200)])
r2 = IntervalSet([Interval(30, 50), Interval(60, 200), Interval(1150, 1300)])
r3 = IntervalSet([Interval(1000, 3000)])
r4 = IntervalSet([Interval(1000, 3000)])
r5 = IntervalSet([Interval(30000, 12000)])
print (r3 - r4), (r4 - r3), r3 & r4
print len(IntervalSet.empty())
if r3 & r4 == r4:
print 'yes'
print(r3 & r4)
if (r3 - r4).empty():
print "true"
print (r3 - r4).empty()
# output
#<Empty> <Empty> [1000..3000]
#0
#yes
#[1000..3000]
#<Empty>
data = [(2,4), (9,13), (6,12)]
Intervals = IntervalSet([Interval.between(min, max) for min, max in data])
print [(_.lower_bound, _.upper_bound) for _ in Intervals]
# output
#[(2, 4), (6, 13)]
|