本文共 1221 字,大约阅读时间需要 4 分钟。
def text_analyzer(text): """Analyze text and count occurrences of each letter, ignoring punctuation and EOF.""" result = {} for a in string.ascii_lowercase: result[a] = text.lower().count(a) return resultdef analysis_result(results): """Process and sort analysis results to generate a formatted output.""" keys = list(results.keys()) values = list(results.values()) values.sort(reverse=True) w2 = {} list_items = [] for key in keys: current = results[key] if current == 0: w2[current] = [key] else: list_items.append(key) w2[current] = list_items keys = list(w2.keys()) keys.sort(reverse=True) for key in keys: items = w2[key] items.sort() for item in items: print(f"{item.upper()} {key}") text = """I have a dream that one day this nation will rise up and live out the truemeaning of its creed: "We hold these truths to be self-evident, that all menare created equal. "I have a dream that my four little children will one daylive in a nation where they will not be Judged by the color of their skin butby the content of their character."""
analysis_result = text_analyzer(text)
转载地址:http://gjlfk.baihongyu.com/