From 13ef118d80ceb0ffc49480f0362caecec9f23667 Mon Sep 17 00:00:00 2001 From: Artem Bilynskyi Date: Mon, 23 Sep 2024 10:01:04 +0300 Subject: [PATCH] Solution --- app/main.py | 22 ++-------------------- 1 file changed, 2 insertions(+), 20 deletions(-) diff --git a/app/main.py b/app/main.py index 2ccc1fdb..00263336 100644 --- a/app/main.py +++ b/app/main.py @@ -1,21 +1,3 @@ def count_occurrences(phrase: str, letter: str) -> int: - """ - Implement count_occurrences function: - - It takes a phrase and a letter and calculates the number of times - the letter appears in the phrase. The function is case insensitive. - - count_occurrences("letter", "t") == 2 - count_occurrences("abc", "a") == 1 - count_occurrences("abc", "d") == 0 - count_occurrences("ABC", "a") == 1 - - :param phrase: phrase to count in it - :param letter: letter to find occurrences of it - :return: count occurrences of letter in phrase - """ - counter = 0 - for i in range(len(phrase)): - if phrase[i].lower() in letter.lower(): - counter += 1 - return counter + return sum([1 for i in range(len(phrase)) + if phrase[i].lower() == letter.lower()])