Skip to content
This repository was archived by the owner on Apr 24, 2020. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions source/rst/python_essentials.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1050,14 +1050,24 @@ Here's one solution:
.. code-block:: python3

def f(string):
count = 0
for letter in string:
if letter == letter.upper() and letter.isalpha():
count += 1
return count
count = 0
for letter in string:
if letter == letter.upper() and letter.isalpha():
count += 1
return count
f('The Rain in Spain')


An alternative, more pythonic solution, would be:

.. code-block:: python3

def count_uppercase_chars(s):
return sum([c.isupper() for c in s])

count_uppercase_chars('The Rain in Spain')


Exercise 4
----------

Expand Down