You can download this code by clicking the button below.
This code is now available for download.
Calculates the occurrence count of each letter (a-z) in the given text.
Technology Stack : collections, string
Code Type : Function
Code Difficulty : Intermediate
def a_to_z_counter(text):
def is_alpha(c):
return c.isalpha()
def get_letter_count(c):
return text.count(c)
from collections import Counter
from string import ascii_lowercase
import string
counter = Counter(text)
letter_counts = {letter: counter[letter] for letter in ascii_lowercase if is_alpha(letter)}
letter_counts = {letter: get_letter_count(letter) for letter in ascii_lowercase if letter in counter}
return letter_counts