Skip to content

Commit

Permalink
Merge pull request #33 from hitblast/optimize-utils
Browse files Browse the repository at this point in the history
🔨 [tuning] Optimize utils using built-in func and list comprehension
  • Loading branch information
hitblast authored Apr 30, 2024
2 parents f535544 + 4084156 commit e8d67e7
Showing 1 changed file with 4 additions and 15 deletions.
19 changes: 4 additions & 15 deletions avro/utils/count.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from avro import config

# SPDX-License-Identifier: MIT


# Import local modules.
from avro import config


# Functions.
Expand All @@ -11,24 +12,12 @@ def count_vowels(text: str) -> int:
Count number of occurrences of vowels in a given string.
"""

count = 0

for i in text:
if i.lower() in config.AVRO_VOWELS:
count += 1

return count
return sum(1 for i in text if i.lower() in config.AVRO_VOWELS)


def count_consonants(text: str) -> int:
"""
Count number of occurrences of consonants in a given string.
"""

count = 0

for i in text:
if i.lower() in config.AVRO_CONSONANTS:
count += 1

return count
return sum(1 for i in text if i.lower() in config.AVRO_CONSONANTS)

0 comments on commit e8d67e7

Please sign in to comment.