June 2023
Intermediate to advanced
316 pages
4h 31m
Japanese
1 #!/usr/bin/env python 2 3 import sys, re, operator, string, traceback 4 5 # 6 # 関数定義 7 # 8 def extract_words(path_to_file): 9 assert(type(path_to_file) is str), "I need a string!" 10 assert(path_to_file), "I need a non-empty string!" 11 12 try: 13 with open(path_to_file) as f: 14 str_data = f.read() 15 except IOError as e: 16 print(f"I/O error({e.errno}) when opening {path_to_file}: {e.strerror}! I quit!") 17 raise e 18 19 pattern = re.compile(r'[\W_]+') 20 word_list = pattern.sub(' ', str_data).lower().split() ...
Read now
Unlock full access