🛠️ToolsShed

文字頻度アナライザー

任意のテキストの文字頻度分布を分析・可視化します。

よくある質問

コード実装

from collections import Counter

def char_frequency(text, case_sensitive=False, include_spaces=True, include_numbers=True):
    if not case_sensitive:
        text = text.lower()
    if not include_spaces:
        text = "".join(c for c in text if not c.isspace())
    if not include_numbers:
        text = "".join(c for c in text if not c.isdigit())
    freq = Counter(text)
    total = sum(freq.values())
    return [
        {"char": ch, "count": cnt, "percent": cnt / total * 100}
        for ch, cnt in freq.most_common()
    ]

text = "Hello, World! Hello Python."
for entry in char_frequency(text)[:5]:
    print(f"'{entry['char']}': {entry['count']} ({entry['percent']:.1f}%)")

Comments & Feedback

Comments are powered by Giscus. Sign in with GitHub to leave a comment.