Skip to content

Update mergesort.py #2441

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

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions divide_and_conquer/mergesort.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,17 @@ def merge(arr, left, mid, right):
return arr


def mergesort(arr, left, right):
def mergesort(arr, left=None, right=None):
"""
>>> mergesort([3, 2, 1], 0, 2)
>>> mergesort([3, 2, 1])
[1, 2, 3]
>>> mergesort([3, 2, 1, 0, 1, 2, 3, 5, 4], 0, 8)
>>> mergesort([3, 2, 1, 0, 1, 2, 3, 5, 4])
[0, 1, 1, 2, 2, 3, 3, 4, 5]
"""
if left is None:
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if left is None:
left = left or 0

All other falsy values are as equally dangerous as None.

Copy link
Author

Choose a reason for hiding this comment

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

I agree, GitHub is not allowing me to send an extra commit to this pull request, I'll close this in favor of #2444

Copy link
Member

@cclauss cclauss Sep 17, 2020

Choose a reason for hiding this comment

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

In the upper right of the file, you should see three dots (...). Click that and select Edit file.

Copy link
Author

Choose a reason for hiding this comment

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

I can't, apparently github doesn't allow adding more commits if you remove your folk

image

left = 0
if right is None:
right = len(arr) - 1
if left < right:
mid = (left + right) // 2
# print("ms1",a,b,m)
Expand Down