Skip to content

Insertion sort : type hint, docstring #2327

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 6 commits into from
Aug 23, 2020
Merged
Changes from 5 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
9 changes: 6 additions & 3 deletions sorts/insertion_sort.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
"""
This is a pure Python implementation of the insertion sort algorithm

This algorithm sorts a collection by comparing adjacent elements.
When it finds that order is not respected, it moves the element compared
backward until order is right.
It then goes back directly to element initial position resuming forward comparison.

Choose a reason for hiding this comment

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

should be "it moves the element by comparing backward until the order is right and insert it there. It then goes back to the element's initial position and resumes forward comparison."

Otherwise, the English sounds weird here.

For doctests run following command:
python -m doctest -v insertion_sort.py
or
python3 -m doctest -v insertion_sort.py

For manual testing run:
python insertion_sort.py
"""


def insertion_sort(collection):
def insertion_sort(collection: list) -> list:
"""Pure implementation of the insertion sort algorithm in Python

:param collection: some mutable ordered collection with heterogeneous
Expand Down