나는 이렇게 학습한다/Algorithm & SQL

1224. Regex count lowercase letters

daco2020 2022. 12. 25. 21:28
반응형

Your task is simply to count the total number of lowercase letters in a string.

Examples

lowercaseCount("abc"); ===> 3

lowercaseCount("abcABC123"); ===> 3

lowercaseCount("abcABC123!@€£#$%^&*()_-+=}{[]|\':;?/>.<,~"); ===> 3

lowercaseCount(""); ===> 0;

lowercaseCount("ABC123!@€£#$%^&*()_-+=}{[]|\':;?/>.<,~"); ===> 0

lowercaseCount("abcdefghijklmnopqrstuvwxyz"); ===> 26



Solution:

def lowercase_count(string: str) -> int:
    return len([i for i in string if i.islower()])
import re

def lowercase_count(string):
    return len(re.findall('[a-z]',string))


반응형