Count Lowercase Letters in Text

  • Share this:

Code introduction


This function accepts a string argument and returns a dictionary containing the count of each lowercase letter in the string.


Technology Stack : collections, string

Code Type : Function

Code Difficulty : Intermediate


                
                    
def a_to_z_counter(text):
    from collections import Counter
    import string

    def is_alpha(char):
        return char.isalpha()

    filtered_text = filter(is_alpha, text)
    counts = Counter(filtered_text)
    return {char: counts[char] for char in string.ascii_lowercase}