mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-07-05 01:09:40 +08:00
Pyupgrade to Python 3.9 (#4718)
* Pyupgrade to Python 3.9 * updating DIRECTORY.md Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from collections import deque
|
||||
from typing import Dict, List, Union
|
||||
|
||||
|
||||
class Automaton:
|
||||
@ -13,7 +14,7 @@ class Automaton:
|
||||
self.add_keyword(keyword)
|
||||
self.set_fail_transitions()
|
||||
|
||||
def find_next_state(self, current_state: int, char: str) -> Union[int, None]:
|
||||
def find_next_state(self, current_state: int, char: str) -> int | None:
|
||||
for state in self.adlist[current_state]["next_states"]:
|
||||
if char == self.adlist[state]["value"]:
|
||||
return state
|
||||
@ -63,7 +64,7 @@ class Automaton:
|
||||
+ self.adlist[self.adlist[child]["fail_state"]]["output"]
|
||||
)
|
||||
|
||||
def search_in(self, string: str) -> Dict[str, List[int]]:
|
||||
def search_in(self, string: str) -> dict[str, list[int]]:
|
||||
"""
|
||||
>>> A = Automaton(["what", "hat", "ver", "er"])
|
||||
>>> A.search_in("whatever, err ... , wherever")
|
||||
|
@ -17,7 +17,7 @@ Time Complexity : O(n/m)
|
||||
n=length of main string
|
||||
m=length of pattern string
|
||||
"""
|
||||
from typing import List
|
||||
from __future__ import annotations
|
||||
|
||||
|
||||
class BoyerMooreSearch:
|
||||
@ -59,7 +59,7 @@ class BoyerMooreSearch:
|
||||
return currentPos + i
|
||||
return -1
|
||||
|
||||
def bad_character_heuristic(self) -> List[int]:
|
||||
def bad_character_heuristic(self) -> list[int]:
|
||||
# searches pattern in text and returns index positions
|
||||
positions = []
|
||||
for i in range(self.textLen - self.patLen + 1):
|
||||
|
@ -1,4 +1,4 @@
|
||||
from typing import List
|
||||
from __future__ import annotations
|
||||
|
||||
|
||||
def kmp(pattern: str, text: str) -> bool:
|
||||
@ -36,7 +36,7 @@ def kmp(pattern: str, text: str) -> bool:
|
||||
return False
|
||||
|
||||
|
||||
def get_failure_array(pattern: str) -> List[int]:
|
||||
def get_failure_array(pattern: str) -> list[int]:
|
||||
"""
|
||||
Calculates the new index we should go to if we fail a comparison
|
||||
:param pattern:
|
||||
|
Reference in New Issue
Block a user