diff options
author | 2021-08-15 22:08:26 +0200 | |
---|---|---|
committer | 2021-08-15 22:08:26 +0200 | |
commit | 54cb20ea9af50c52fda40fe468470f4e7d351fed (patch) | |
tree | 7e8d1f9d34a22d5ec709a8599bb181e1d9e2acb0 | |
parent | Fix incorrect annotation (diff) |
refactor fuzzy_search to use conventional iteration
Co-authored-by: Bluenix <[email protected]>
-rw-r--r-- | bot/exts/info/tags.py | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/bot/exts/info/tags.py b/bot/exts/info/tags.py index 5632f2959..d659be8c4 100644 --- a/bot/exts/info/tags.py +++ b/bot/exts/info/tags.py @@ -117,15 +117,13 @@ def _fuzzy_search(search: str, target: str) -> float: current, index = 0, 0 _search = REGEX_NON_ALPHABET.sub("", search.lower()) _targets = iter(REGEX_NON_ALPHABET.split(target.lower())) - _target = next(_targets) - try: - while True: - while index < len(_target) and _search[current] == _target[index]: - current += 1 - index += 1 - index, _target = 0, next(_targets) - except (StopIteration, IndexError): - pass + + for _target in _targets: + while index < len(_target) and _search[current] == _target[index]: + current += 1 + index += 1 + index = 0 + return current / len(_search) |