Skip to content

Commit ba8cc67

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent b1b4caf commit ba8cc67

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

strings/anagrams.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
def signature(word: str) -> str:
1010
"""
1111
Return a word sorted by its letters.
12-
12+
1313
>>> signature("test")
1414
'estt'
1515
>>> signature("this is a test")
@@ -23,7 +23,7 @@ def signature(word: str) -> str:
2323
def anagram(my_word: str) -> List[str]:
2424
"""
2525
Return every anagram of the given word.
26-
26+
2727
>>> anagram('test')
2828
['sett', 'stet', 'test']
2929
>>> anagram('this is a test')

strings/autocomplete_using_trie.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
END = "#"
55

6+
67
class Trie:
78
def __init__(self) -> None:
89
self._trie: Dict[str, Union[Dict, bool]] = {}
@@ -30,6 +31,7 @@ def find_word(self, prefix: str) -> Union[List[str], Tuple[str, ...]]:
3031

3132
def delete_word(self, word: str) -> None:
3233
"""Deletes a word from the trie if it exists, case insensitive."""
34+
3335
def _delete(node: Dict[str, Union[Dict, bool]], word: str, depth: int) -> bool:
3436
if depth == len(word):
3537
if END in node:
@@ -41,7 +43,7 @@ def _delete(node: Dict[str, Union[Dict, bool]], word: str, depth: int) -> bool:
4143
del node[char]
4244
return len(node) == 0
4345
return False
44-
46+
4547
_delete(self._trie, word.lower(), 0)
4648

4749
def _elements(self, node: Dict[str, Union[Dict, bool]]) -> Tuple[str, ...]:
@@ -55,6 +57,7 @@ def _elements(self, node: Dict[str, Union[Dict, bool]]) -> Tuple[str, ...]:
5557
result.extend(sub_result)
5658
return tuple(result)
5759

60+
5861
# Example usage of the enhanced Trie class
5962
def autocomplete_using_trie(prefix: str, trie: Trie) -> Tuple[str, ...]:
6063
"""
@@ -74,6 +77,7 @@ def autocomplete_using_trie(prefix: str, trie: Trie) -> Tuple[str, ...]:
7477
suffixes = trie.find_word(prefix)
7578
return tuple(prefix + suffix for suffix in suffixes)
7679

80+
7781
def main() -> None:
7882
trie = Trie()
7983
words = ("depart", "detergent", "daring", "dog", "deer", "deal")
@@ -83,7 +87,9 @@ def main() -> None:
8387
trie.delete_word("detergent")
8488
print(autocomplete_using_trie("de", trie))
8589

90+
8691
if __name__ == "__main__":
8792
import doctest
93+
8894
doctest.testmod()
8995
main()

0 commit comments

Comments
 (0)