Letter Frequency Counter

  • Share this:

Code introduction


This function counts the occurrences of each letter in the input text and returns a dictionary where the keys are letters and the values are the number of times each letter appears in the text.


Technology Stack : collections.Counter, string.ascii_lowercase

Code Type : Counting function

Code Difficulty : Intermediate


                
                    
def a_to_z_counter(text):
    from collections import Counter
    from string import ascii_lowercase
    
    count = Counter(text.lower())
    return {char: count[char] for char in ascii_lowercase if char in count}