...

/

Solution: Calculate the Number of Uppercase and Lowercase Letters

Solution: Calculate the Number of Uppercase and Lowercase Letters

Learn how to write a function to calculate the number of uppercase and lowercase letters in Python.

We'll cover the following...

The solution to the problem of calculating the number of uppercase and lowercase letters in Python is given below.

Solution

Press + to interact
def count_lower_upper(s) :
dlu = {'Lower' : 0, 'Upper' : 0}
for ch in s :
if ch.islower( ) :
dlu['Lower'] += 1
elif ch.isupper( ) :
dlu['Upper'] += 1
return(dlu)
d = count_lower_upper('James BOnd ')
print(d)

Explanation

  • Line 2:
...