파이썬에서 대문자로 시작하는 모든 문자를 가져 오는 작은 스 니펫을 작성하고 있습니다. 여기 내 코드가문자열에서 대문자로 시작하는 모든 단어를 검색하는 코드
def WordSplitter(n):
list1=[]
words=n.split()
print words
#print all([word[0].isupper() for word in words])
if ([word[0].isupper() for word in words]):
list1.append(word)
print list1
WordSplitter("Hello How Are You")
위의 코드를 실행할 때. Im은 문자열에있는 모든 단어가 대문자로 시작하기 때문에 문자열의 모든 요소를 포함 할 것으로 기대합니다. 그러나 여기 내 출력입니다 :
@ubuntu:~/py-scripts$ python wordsplit.py
['Hello', 'How', 'Are', 'You']
['You']# Im expecting this list to contain all words that start with a capital letter
삭제 된 답변에서도 제안되었지만 대문자로 시작하는'CamelCase'는 처리 할 수 없지만 ' 'CamelCase'.stititle()'은 거짓입니다. 'ALLCAPS'와 비슷합니다. – DSM