-
-
Notifications
You must be signed in to change notification settings - Fork 46.8k
Update linear_search.py #2422
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
Update linear_search.py #2422
Conversation
Python implementation of recursive linear search algorithm
@Ashley-J-George Hi there, Your first PR ever huh? Good luck! It looks like you did not provide any doctests for There is an issue when, for example, Also, type hints for both def rec_linear_search(sequence: list, low: int, high: int, target: float) -> int: |
Added different doctests Added the parameter hints Handled the exception
Hey @Ashley-J-George, TravisCI finished with status TravisBuddy Request Identifier: 340dc310-f65d-11ea-afed-a1bc0e34d213 |
Hey @Ashley-J-George, TravisCI finished with status errored, which means the build failed because of something unrelated to the tests, such as a problem with a dependency or the build process itself. @cclauss @spamegg1 How should I rectify this? My actual code is ` def rec_linear_search(sequence: list, low: int, high: int, target: int) -> int:
def main():
if name == 'main': ` |
When the element is not found I have made the function return -1, and added
a try except to handle the index error
…On Mon, Sep 14, 2020 at 1:08 PM Christian Clauss ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In searches/linear_search.py
<#2422 (comment)>:
> +
+ Examples:
+ >>> linear_search([0, 5, 7, 10, 15], 0)
+ 0
+
+ >>> linear_search([0, 5, 7, 10, 15], 15)
+ 4
+
+ >>> linear_search([0, 5, 7, 10, 15], 5)
+ 1
+
+ >>> linear_search([0, 5, 7, 10, 15], 6)
+
+ '''
+ if high < low:
+ return None
We promised on line 41 that this function would return an it but now we
are returning an non-int. We have two choices:
1. Return -1 as a signal that the element is not in the list --or--
2. Raise an error.
This is like str.find()
<https://docs.python.org/3/library/stdtypes.html#str.find> vs. str.index
<https://docs.python.org/3/library/stdtypes.html#str.index>.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#2422 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AJUYHLIMUQZOAKBQSFPDUITSFXB6PANCNFSM4RK2FGDQ>
.
|
added parameter hints to linear_search
Hey @Ashley-J-George, TravisCI finished with status TravisBuddy Request Identifier: 156ed5e0-f660-11ea-afed-a1bc0e34d213 |
@Ashley-J-George Build log says
Very easy to fix! Check out CONTRIBUTING.md about running |
Both the functions return the index if the target is found and -1 if it is not found The rec_linear_search raises an exception if there is an indexing problem Made changes in the doc comments
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.
Nice work!!
Thank You! |
* Update linear_search.py Python implementation of recursive linear search algorithm * Update linear_search.py Added different doctests Added the parameter hints Handled the exception * Update linear_search.py added parameter hints to linear_search * Update linear_search.py Both the functions return the index if the target is found and -1 if it is not found The rec_linear_search raises an exception if there is an indexing problem Made changes in the doc comments * Update linear_search.py Co-authored-by: Christian Clauss <cclauss@me.com>
I've added a Python implementation of recursive search algorithm
Describe your change:
Checklist:
Fixes: #{$ISSUE_NO}
.