From 1aca7170256fb83eb3408ef04affa3282b74ce24 Mon Sep 17 00:00:00 2001 From: Viktoriia Danylchuk Date: Thu, 12 Sep 2024 12:06:27 +0300 Subject: [PATCH 1/3] 'Solution' --- README.md | 4 ---- app/main.py | 6 +++++- 2 files changed, 5 insertions(+), 5 deletions(-) delete mode 100644 README.md diff --git a/README.md b/README.md deleted file mode 100644 index 740f7b97..00000000 --- a/README.md +++ /dev/null @@ -1,4 +0,0 @@ -# Count Occurrences - -- Read [the guideline](https://github.com/mate-academy/py-task-guideline/blob/main/README.md) before start -- Implement the task described [here](app/main.py) diff --git a/app/main.py b/app/main.py index 4ccbb02b..62c80aac 100644 --- a/app/main.py +++ b/app/main.py @@ -14,4 +14,8 @@ def count_occurrences(phrase: str, letter: str) -> int: :param letter: letter to find occurrences of it :return: count occurrences of letter in phrase """ - # write your code here + counter = 0 + for char in phrase: + if char.lower() == letter.lower(): + counter += 1 + return counter From 6f2b53db89268554c9dccc6b941090c4ce1199e8 Mon Sep 17 00:00:00 2001 From: Viktoriia Danylchuk Date: Thu, 12 Sep 2024 12:29:25 +0300 Subject: [PATCH 2/3] 'Solution1' --- app/main.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/main.py b/app/main.py index 62c80aac..f825d4f2 100644 --- a/app/main.py +++ b/app/main.py @@ -16,6 +16,5 @@ def count_occurrences(phrase: str, letter: str) -> int: """ counter = 0 for char in phrase: - if char.lower() == letter.lower(): - counter += 1 + counter += (char.lower() == letter.lower()) return counter From 58f0b1f87083a601191c5ba359292faf3600b738 Mon Sep 17 00:00:00 2001 From: Viktoriia Danylchuk Date: Thu, 12 Sep 2024 14:06:44 +0300 Subject: [PATCH 3/3] Sollution in one line --- app/main.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/app/main.py b/app/main.py index f825d4f2..8b0f5717 100644 --- a/app/main.py +++ b/app/main.py @@ -14,7 +14,4 @@ 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: - counter += (char.lower() == letter.lower()) - return counter + return phrase.lower().count(letter.lower())