From 90a1d86cbd987271e1f773aebf4a923bb0fb1238 Mon Sep 17 00:00:00 2001 From: Vitalii Burkalo Date: Wed, 17 Jan 2024 21:33:09 +0200 Subject: [PATCH] rewriten function using method count of string --- app/main.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/app/main.py b/app/main.py index 62c80aac..e56ad279 100644 --- a/app/main.py +++ b/app/main.py @@ -14,8 +14,7 @@ def count_occurrences(phrase: str, letter: str) -> int: :param letter: letter to find occurrences of it :return: count occurrences of letter in phrase """ - counter = 0 - for char in phrase: - if char.lower() == letter.lower(): - counter += 1 - return counter + return phrase.lower().count(letter.lower()) + + +print(count_occurrences("ABC", "a"))