-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1910 from vsmutok/update-readme
- Loading branch information
Showing
2 changed files
with
37 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,39 @@ | ||
# 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) | ||
|
||
## Task Description | ||
|
||
You are required to implement the `count_occurrences` function that takes two parameters: | ||
|
||
1. **phrase**: A string in which to count occurrences of a letter. | ||
2. **letter**: The letter whose occurrences need to be counted in the given phrase. | ||
|
||
The function should return the number of times the letter appears in the phrase, while being **case insensitive**. | ||
|
||
### Examples: | ||
|
||
- `count_occurrences("letter", "t")` should return `2` | ||
- `count_occurrences("abc", "a")` should return `1` | ||
- `count_occurrences("abc", "d")` should return `0` | ||
- `count_occurrences("ABC", "a")` should return `1` | ||
|
||
### Function Signature: | ||
|
||
```python | ||
def count_occurrences(phrase: str, letter: str) -> int: | ||
""" | ||
Count occurrences of a letter in a phrase (case insensitive). | ||
:param phrase: The phrase to search within. | ||
:param letter: The letter to count occurrences of. | ||
:return: The number of occurrences of the letter in the phrase. | ||
""" | ||
``` | ||
|
||
## Guidelines | ||
|
||
- The function must be **case insensitive**. This means that both the phrase and the letter should be treated as if they are in the same case (upper or lower). | ||
|
||
- It is **recommended** to avoid using loops to solve this task. Instead, consider utilizing Python's built-in string functions to simplify the solution. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +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 | ||
""" | ||
# write your code here | ||
pass |