Advertisement
DenCoder618

Untitled

Sep 17th, 2023
784
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.43 KB | None | 0 0
  1. def frequency_analysis(text):
  2.     frequencies = dict()
  3.     total_chars = 0
  4.  
  5.     for char in text:
  6.         if char.isalpha():
  7.             char = char.lower()
  8.             frequencies[char] = frequencies.get(char, 0) + 1
  9.             total_chars += 1
  10.  
  11.     items = frequencies.items()
  12.     for char, count in sorted(items, key=lambda i: i[0]):
  13.         frequency = count / total_chars * 100
  14.         print(f"{char}: {frequency:.2f}%")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement