Skip to content

Largest subarray sum #1404

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

Merged
merged 10 commits into from
Oct 22, 2019
Merged

Largest subarray sum #1404

merged 10 commits into from
Oct 22, 2019

Conversation

anubhav-sharma13
Copy link
Contributor

@anubhav-sharma13 anubhav-sharma13 commented Oct 19, 2019

It contains the code of how to find the largest subarray sum in Python.

@cclauss
Copy link
Member

cclauss commented Oct 19, 2019

Travis CI tests are failing. See CONTRIBUTING.md for details.

This repo no longer supports legacy Python. print() is a function in Python 3.

https://travis-ci.com/TheAlgorithms/Python/builds/132670589#L352

@cclauss cclauss added the tests are failing Do not merge until tests pass label Oct 19, 2019
Copy link
Member

@cclauss cclauss left a comment

Choose a reason for hiding this comment

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

print()

@cclauss
Copy link
Member

cclauss commented Oct 21, 2019

sys.maxint was removed in Python 3 because all integers are of infinite precision.
https://docs.python.org/3/whatsnew/3.0.html#integers

@cclauss
Copy link
Member

cclauss commented Oct 21, 2019

This is what a Pythonic function name, type hints, a doctest, and a default argument would look like.

def max_sub_array_sum(a: list, size: int = 0):
    """
    >>> max_sub_array_sum([-13, -3, -25, -20, -3, -16, -23, -12, -5, -22, -15, -4, -7])
    -3
    """
    size = size or len(a)

@cclauss
Copy link
Member

cclauss commented Oct 21, 2019

@anubhav-sharma13
Copy link
Contributor Author

It is working on my system but the travis CI test failed

@cclauss
Copy link
Member

cclauss commented Oct 21, 2019

On your system, what happens when you type:

  • python3 -m doctest largest_subarray_sum.py
  • python3 -m doctest -v largest_subarray_sum.py

@cclauss
Copy link
Member

cclauss commented Oct 21, 2019

Doctests are just docstrings until you run python3 -m doctest on them and then they turn into tests!

The problem that Travis is complaining about is that the doctest is using a Pythonic function name but the code is using a JavaScript-style function name.

@@ -1,5 +1,5 @@
from sys import maxsize
def maxSubArraySum(a: list, size: int = 0):
def max_Sub_Array_Sum(a: list, size: int = 0):
"""
>>> max_sub_array_sum([-13, -3, -25, -20, -3, -16, -23, -12, -5, -22, -15, -4, -7])
Copy link
Member

Choose a reason for hiding this comment

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

Let’s be Pythonic and use max_sub_array_sum everywhere.

@cclauss cclauss merged commit ce7faa5 into TheAlgorithms:master Oct 22, 2019
stokhos pushed a commit to stokhos/Python that referenced this pull request Jan 3, 2021
* Insertion_sort

* largest subarray sum

* updated print command

* removed extraspaces

* removed sys.maxint

* added explaination

* Updated function style

* Update largest_subarray_sum.py

* Update i_sort.py

* Delete bogo_bogo_sort.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tests are failing Do not merge until tests pass
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants