You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Each letter and digit we use has a corresponding unique Unicode integer value. We can get this value using Python's built-in ord() function. Knowing which integers represent upper- and lower-case letters, which represent the digits 0 through 9 we can then use the len() function and list comprehension to determine the number of letters and digits. My solution avoids unwieldy if else conditions etc.
Thoughts?
def count_ld(x):
return print(f'LETTERS {len([v for v in x if ord(v) in range(65, 91) or ord(v) in range(97,123)])}\nDIGIT {len([v for v in x if ord(v) in range(48,54)])}')
count_ld(input("ENTER: "))
The text was updated successfully, but these errors were encountered:
Each letter and digit we use has a corresponding unique Unicode integer value. We can get this value using Python's built-in ord() function. Knowing which integers represent upper- and lower-case letters, which represent the digits 0 through 9 we can then use the len() function and list comprehension to determine the number of letters and digits. My solution avoids unwieldy if else conditions etc.
Thoughts?
def count_ld(x):
return print(f'LETTERS {len([v for v in x if ord(v) in range(65, 91) or ord(v) in range(97,123)])}\nDIGIT {len([v for v in x if ord(v) in range(48,54)])}')
count_ld(input("ENTER: "))
The text was updated successfully, but these errors were encountered: