Letter Case Counter

Write a Python function named count_letters that accepts a string and returns a tuple where the first element is the number of upper case letters and the second is the number of lower case letters in the string.

Example 1:

Input: count_letters('Hello World') 
Output: (2, 8)

Example 2:

Input: count_letters('GOOD Morning') 
Output: (6, 7)

Use the string methods isupper() and islower() to count the uppercase and lowercase letters.

def count_letters(s):
    return sum(1 for c in s if c.isupper()), sum(1 for c in s if c.islower())

© Let’s Data Science

LOGIN

Unlock AI & Data Science treasures. Log in!