11#!/usr/bin/env python3
22
3- import sys
4- import os
53import bisect
6- from collections import defaultdict
7- from typing import IO , Dict , List
8- from collections import deque
4+ import os
5+ import sys
6+ from collections import defaultdict , deque
97from operator import itemgetter
8+ from pathlib import Path
9+ from typing import IO
1010
1111
1212class TrieNode :
13- def __init__ (self ):
13+ def __init__ (self ) -> None :
1414 # Initialize TrieNode attributes
15- self .children : Dict [str , TrieNode ] = defaultdict (TrieNode )
16- self .output : List [str ] = []
15+ self .children : dict [str , TrieNode ] = defaultdict (TrieNode )
16+ self .output : list [str ] = []
1717 self .fail : TrieNode | None = None
1818
1919
@@ -116,10 +116,6 @@ def main(fptr: IO) -> None:
116116 len_min = min (len_min , len (g ))
117117 alphabet .update (list (g ))
118118
119- print (
120- f"Alphabet of { len (alphabet )} , genes length between { len_min } and { len_max } , { len (genes_dict )} genes, { s } strands"
121- )
122-
123119 dnas = []
124120 for _ in range (s ):
125121 first_multiple_input = input ().rstrip ().split ()
@@ -132,7 +128,6 @@ def main(fptr: IO) -> None:
132128 min_h = sys .maxsize
133129
134130 if len_min == len_max :
135- print ("Fast Mode!" )
136131 for first , last , d in dnas :
137132 h = 0
138133 for i in range (len (d ) - len_min + 1 ):
@@ -144,7 +139,6 @@ def main(fptr: IO) -> None:
144139
145140 else :
146141 # Build the Aho-Corasick automaton
147- print ("Aho-Corasick!" )
148142 genes_unique = set (genes )
149143 trie = build_automaton (genes_unique )
150144 for first , last , d in dnas :
@@ -156,8 +150,8 @@ def main(fptr: IO) -> None:
156150
157151
158152if __name__ == "__main__" :
159- if "OUTPUT_PATH" in os .environ :
160- with open ( os . environ [ "OUTPUT_PATH" ], "wt " ) as fptr :
153+ if path := os .getenv ( "OUTPUT_PATH" ) :
154+ with Path ( path ). open ( "wt" , encoding = "utf-8 " ) as fptr :
161155 main (fptr )
162156 fptr .close ()
163157 else :
0 commit comments