Counting Lowercase Letter Frequencies in Text

  • Share this:

Code introduction


This function counts the occurrence of each letter (in lowercase) in the input string and returns a dictionary where the keys are the letters and the values are their counts. If a letter does not appear in the input string, it will not be included in the resulting dictionary.


Technology Stack : collections, string

Code Type : Function

Code Difficulty : Intermediate


                
                    
def a_to_z_count(text):
    from collections import Counter
    from string import ascii_lowercase

    count = Counter(text.lower())
    result = {char: count[char] for char in ascii_lowercase if char in count}
    return result