Skip to content

Commit a097b6d

Browse files
committed
improved potential performance by switching list to set and removing unnecessary sorting
1 parent e84ebf6 commit a097b6d

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

Sprint-2/improve_with_precomputing/count_letters/count_letters.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@ def count_letters(s: str) -> int:
44
"""
55
only_upper = 0
66
only_uniq = set(s)
7-
only_uniq_sorted = sorted(only_uniq)
8-
uppercase = [ch for ch in only_uniq_sorted if ch.isupper()]
9-
lowercase = [ch for ch in only_uniq_sorted if ch.islower()]
7+
uppercase = set(ch for ch in only_uniq if ch.isupper())
8+
lowercase = set(ch for ch in only_uniq if ch.islower())
109
for i in uppercase:
1110
if i.lower() not in lowercase:
1211
only_upper += 1

0 commit comments

Comments
 (0)