-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Q14 Improved Solution #147
Comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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: