Skip to main content

520. Detect Capital

Python

from string import ascii_lowercase, ascii_uppercase


class Solution:
def detectCapitalUse(self, word: str) -> bool:
if word[0] in ascii_uppercase:
uppers = [char for char in word[1:] if char in ascii_lowercase]
if len(uppers) == 0:
return True
return len(uppers) == len(word) - 1

for char in word[1:]:
if char in ascii_uppercase:
return False
return True