Learn data science and machine learning by building real-world projects on Jovian
# exercise 5
Count all lower case, upper case, digits, and special symbols from a given string Given:
str1 = "P@#yn26at^&i5ve"
Expected Outcome:
Total counts of chars, digits,and symbols
Chars = 8 Digits = 3 Symbol = 4
str1 = "P@#yn26at^&i5ve"
char_set_small = [i for i in range(ord('a'),ord('z')+1)]
result = {'Chars':0, 'Digits':0, 'Symbol':0}
digit_set = [i for i in range(ord('0'),ord('9')+1)]
for i in str1:
    char = i.lower()
    if ord(char) in char_set_small:
        result['Chars'] +=1
    elif ord(char) in digit_set:
        result['Digits'] +=1
        result['Symbol'] +=1
{'Chars': 8, 'Digits': 3, 'Symbol': 4}
import jovian
[jovian] Attempting to save notebook..