with open('my_textfile.txt', 'r') as text: print(sum(word.istitle() for row in text for word in row))