How to count the number of capital letters in a file?
Your code should work even if the file is too big to fit in memory. ______
We need to write a multiple line solution and then convert it to one liner code.
Example:
with open(SOME_LARGE_FILE) as fh:
count = 0
text = fh.read()
for character in text:
if character.isupper():
count += 1
We will now try to transform this into a single line:
count sum(1 for line in fh for character in line if character.isupper())