Pythonで大文字で始まるすべての文字を取得する小さなスニペットを書いています。これが私のコードです
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")
上記のコードを実行すると、リスト内のすべての単語は大文字で始まるため、リストには文字列のすべての要素が含まれることを期待しています。しかし、これが私の出力です:
@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