Skip to content
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

Open
Euan-J-Austin opened this issue Nov 30, 2023 · 0 comments
Open

Q14 Improved Solution #147

Euan-J-Austin opened this issue Nov 30, 2023 · 0 comments

Comments

@Euan-J-Austin
Copy link

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: "))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant