문자 빈도 분석기
모든 텍스트의 문자 빈도 분포를 분석하고 시각화합니다.
자주 묻는 질문
코드 구현
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.