Skip to content
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 limit.py #374

Closed
wants to merge 1 commit into from
Closed

Update limit.py #374

wants to merge 1 commit into from

Conversation

ggran-REN
Copy link

@ggran-REN ggran-REN commented Jul 9, 2018

there are some syntax warnings in this code.
there maybe another logical error:
in this code, when parameter min_lim and parameter max_lim are both None, it will not hit any if judgment, result will return [].
however it should return arr[::] actually.

(Put an X inside the [ ] to denote check mark [X].)

  • If creating a new file :

    • added links to it in the README files ?
    • included tests with it ?
    • added description (overview of algorithm, time and space compleixty, and possible edge case) in docstrings ?
  • if done some changes :

    • wrote short description in the PR explaining what the changes do ?
    • Fixes #[issue number] if related to any issue
  • other

there are some syntax warnings in this code.
there maybe another logical error: 
in this code, when parameter min_lim and parameter max_lim are both None, it will not hit any if judgment, result will return []. 
however it should return arr[::] actually.
@coveralls
Copy link

Pull Request Test Coverage Report for Build 673

  • 10 of 11 (90.91%) changed or added relevant lines in 1 file are covered.
  • 1 unchanged line in 1 file lost coverage.
  • Overall coverage increased (+0.008%) to 71.582%

Changes Missing Coverage Covered Lines Changed/Added Lines %
algorithms/arrays/limit.py 10 11 90.91%
Files with Coverage Reduction New Missed Lines %
algorithms/linkedlist/is_palindrome.py 1 93.33%
Totals Coverage Status
Change from base Build 667: 0.008%
Covered Lines: 3796
Relevant Lines: 5303

💛 - Coveralls

result.append(i)
elif max_lim == None:
elif min_lim and max_lim is None:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ggran-REN The syntax warnings maybe in these if conditions. What if min_lim is 0, then the code fails.
Consider the case where I give limit(arr, 0, 0), I would expect [], but will get same array instead.
All this can simply be solved by:

def limit(arr, min_lim=None, max_lim=None):
    if min_lim is None:
        min_lim = float("-infinity")
    if max_lim is None:
        max_lim = float("infinity")
    result = []
    for i in arr:
        if min_lim <= i <= max_lim:
            result.append(i)
    return result

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thasks alot :-)!
i overlooked 0 is always False in python~

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ggran-REN I see that you are a first-time contributor, its great :).
BTW, you can fix the code in your branch ggran-REN:patch-1 to reflect changes in this PR. Thanks.

if i < min_lim:
continue
if i > max_lim:
continue
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit
you could probably merge these two ifs into a single if statement.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

watch you tongue fool

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

im confused

@QuanDo2000
Copy link

There is currently a shorter implementation of limit.py in arrays so we should close this PR.

@keon keon closed this Nov 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants