[Python] Python function & Procedure approach[Python] Python function & Procedure approach

🕵️

The Secret Order

Week 3, 2026

def read_file(filename: str) -> list[str]: try: with open(filename, "r") as file: return file.read().strip().split() except IOError: raise IOError(f"File {filename} could not be found") def is_abecedarian(word: str) -> bool: return list(word) == sorted(list(word)) def save_file(filename: str, words: list[str]) -> None: with open(filename, 'w', encoding='utf-8') as file: file.writelines(word + '\n' for word in words) #Driver Code words: list[str] = read_file("words.txt") accepted_words = [word for word in words if is_abecedarian(word) and len(word) > 1] save_file("answer.txt", accepted_words)