-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
completed the task , py-count-occurences #678
base: master
Are you sure you want to change the base?
Conversation
app/main.py
Outdated
@@ -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 | |||
count = 0 | |||
for i in range(len(phrase)): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can iterate through elements instead of indexes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes requested
Edit solutions |
app/main.py
Outdated
count = 0 | ||
for char in phrase: | ||
if char.lower() == letter.lower(): | ||
count += 1 | ||
return count |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can write this inline instead of loop
app/main.py
Outdated
# write your code here | ||
""""" | ||
|
||
return sum(1 for i in phrase if i.lower() == letter.lower()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is i
? use more accurate name
app/main.py
Outdated
return sum(1 for character in phrase | ||
if character.lower() == letter.lower()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need to use sum
use count
No description provided.