https://github.com/pymorphy2-fork/DAWG-Python/blob/b7fc89348029b65b7ef3eb55b34bc4c230fdde12/dawg_python/wrapper.py#L97C13-L97C13
In fact, Completer is an implementation of the Iterator pattern. So, I think it makes sense to rewrite it as a Python iterator. Or, add .keys() and .values() methods, which would return iterators.
E.g. rewrite from:
class Completer:
...
def init(self, ...):
...
def next(self):
...
to
class Completer:
...
def __iter__(self):
...
def __next__(self):
...
So that it can be used as:
res = [item.decode("utf8") for item in completer]
instead of
res = []
while completer.next():
key = completer.key.decode('utf8')
res.append(key)
return res
Or
yield from (item.decode("utf8") for item in completer)
instead of
while completer.next():
yield completer.key.decode('utf8')
https://github.com/pymorphy2-fork/DAWG-Python/blob/b7fc89348029b65b7ef3eb55b34bc4c230fdde12/dawg_python/wrapper.py#L97C13-L97C13
In fact, Completer is an implementation of the Iterator pattern. So, I think it makes sense to rewrite it as a Python iterator. Or, add
.keys()and.values()methods, which would return iterators.E.g. rewrite from:
to
So that it can be used as:
instead of
Or
instead of