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

empty list returned without sorting #25

Merged
merged 4 commits into from
Aug 29, 2024
Merged

Conversation

gertingold
Copy link
Contributor

@gertingold gertingold commented Aug 27, 2024

This PR proposes to handle empty lists like lists of length 1 and to return the list unmodified. This solution should fix #8

@@ -21,7 +21,7 @@ def merge_sort(l):
sorted_list
"""
# If there is a single item, the list is already sorted, return.
if len(l) == 1:
if 0 <= len(l) <= 1:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
if 0 <= len(l) <= 1:
if len(l) <= 1:

I think it would be clearer to delete this, since the length cannot be negative.

(since it is a small change, one can just apply it. Often I would just do that as a maintainer)

@gertingold
Copy link
Contributor Author

Of course there should be a test :-) After all, there was already a stub.

@Nikoleta-v3
Copy link
Owner

Thank you gertingold 😄 @seberg should we fix the merge conflict and merge?

@seberg
Copy link
Collaborator

seberg commented Aug 29, 2024

Thank you gertingold 😄 @seberg should we fix the merge conflict and merge?

Yap, looks all good to me, thanks. Can't even find a nitpick :).

@seberg seberg merged commit 7964074 into Nikoleta-v3:main Aug 29, 2024
4 checks passed
@seberg
Copy link
Collaborator

seberg commented Aug 29, 2024

Thanks @gertingold.

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.

BUG: merge_sort hangs when sorting an empty list
3 participants