Skip to content

Commit e3423bd

Browse files
committed
Change old style named tuple into new style
1 parent 72b57b0 commit e3423bd

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

source_code/intersection_trees/naive_pythonic_intersectionic_queries.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,24 @@
22
Naive and very Pythonic implementation of interval intersection queries.
33
'''
44

5-
import collections
65
import itertools
76
import random
87
import typing
98

109

11-
Interval = collections.namedtuple('Interval', ('s', 'e'))
10+
class Interval(typing.NamedTuple):
11+
'''A half-open interval [s, e)
12+
13+
Attributes
14+
----------
15+
s: int
16+
start of the interval, inclusive
17+
e: int
18+
end of the interval, exclusive
19+
'''
20+
s: int
21+
e: int
22+
1223
Db: typing.TypeAlias = set[Interval]
1324
Queries: typing.TypeAlias = Db
1425
QueryResult: typing.TypeAlias = set[tuple[Interval, Interval]]
@@ -106,4 +117,4 @@ def execute_queries(queries: Queries, db: Db) -> QueryResult:
106117
QueryResult
107118
set of tuples of query and database intervals that intersect
108119
'''
109-
return {(q, d) for q, d in itertools.product(queries, db) if have_intersection(q, d)}
120+
return {(q, d) for q, d in itertools.product(queries, db) if have_intersection(q, d)}

0 commit comments

Comments
 (0)