forked from conspack/pyconspack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.py
More file actions
28 lines (20 loc) · 645 Bytes
/
index.py
File metadata and controls
28 lines (20 loc) · 645 Bytes
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
__all__ = ["Index"]
import pyconspack.types as T
class Index:
def __init__(self, vals):
def maybe_keyword(x):
if (type(x) is str):
return T.keyword(x)
return x
self.index = dict()
self.vals = map(maybe_keyword, vals)
for i, val in enumerate(self.vals):
self.index[val] = i
def __contains__(self, x):
return x in self.index
def __getitem__(self, x):
return self.index[x]
def index(self, i):
return (i < len(self.vals)) and self.vals[i]
def __str__(self):
return '<Index: ' + self.index.__str__() + '>'