Skip to content

Merge sort#10

Open
markreynoso wants to merge 74 commits intomasterfrom
merge
Open

Merge sort#10
markreynoso wants to merge 74 commits intomasterfrom
merge

Conversation

@markreynoso
Copy link
Copy Markdown
Owner

No description provided.

```
Merge sort takes in a list of numbers and uses an merge sort method to return a sorted list.

To use merge_sort, from merge_sort import merge_sort.
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Probably put back-ticks around the import statement here to further distinguish the code that someone would write from the text that's explaining what's happening

"""Sort a list using the merge sort method."""
if len(list_in) > 1:
half = len(list_in) // 2
list_a = list_in[0:half]
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

You don't need to start this with a 0. If you provide no integer for the first argument of the slice, it'll start at 0 by default

while l_idx < len(left) and r_idx < len(right):
if left[l_idx] < right[r_idx]:
output.append(left[l_idx])
l_idx = l_idx + 1
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This can be shortened with l_idx += 1

r_idx = r_idx + 1
while l_idx < len(left):
output.append(left[l_idx])
l_idx = l_idx + 1
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This and the following statements could be two-line if statements that are less obvious iterative processes:

if l_idx < len(left) - 1:
    output.extend(left[l_idx:])
el r_idx < len(right) - 1:
    output.extend(right[r_idx:])

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.

3 participants