Skip to content
This repository was archived by the owner on Apr 24, 2020. It is now read-only.

Commit a8c4795

Browse files
author
Jez
committed
Changed the implementation of exercise 3 in python essentials to make it
faster, more pythonic and use techniques explained in the text
1 parent b04109d commit a8c4795

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

source/rst/python_essentials.rst

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,13 +1049,10 @@ Here's one solution:
10491049

10501050
.. code-block:: python3
10511051
1052-
def f(string):
1053-
count = 0
1054-
for letter in string:
1055-
if letter == letter.upper() and letter.isalpha():
1056-
count += 1
1057-
return count
1058-
f('The Rain in Spain')
1052+
def count_uppercase_chars(s):
1053+
return sum([c.isupper() for c in s]
1054+
1055+
count_uppercase_chars('The Rain in Spain')
10591056
10601057
10611058
Exercise 4

0 commit comments

Comments
 (0)