File tree Expand file tree Collapse file tree 1 file changed +10
-7
lines changed
Expand file tree Collapse file tree 1 file changed +10
-7
lines changed Original file line number Diff line number Diff line change 11"""
2- This is a pure Python implementation of the insertion sort algorithm
2+ A pure Python implementation of the insertion sort algorithm
3+
4+ This algorithm sorts a collection by comparing adjacent elements.
5+ When it finds that order is not respected, it moves the element compared
6+ backward until the order is correct. It then goes back directly to the
7+ element's initial position resuming forward comparison.
38
49For doctests run following command:
5- python -m doctest -v insertion_sort.py
6- or
710python3 -m doctest -v insertion_sort.py
811
912For manual testing run:
10- python insertion_sort.py
13+ python3 insertion_sort.py
1114"""
1215
1316
14- def insertion_sort (collection ) :
15- """Pure implementation of the insertion sort algorithm in Python
17+ def insertion_sort (collection : list ) -> list :
18+ """A pure Python implementation of the insertion sort algorithm
1619
1720 :param collection: some mutable ordered collection with heterogeneous
1821 comparable items inside
@@ -47,4 +50,4 @@ def insertion_sort(collection):
4750if __name__ == "__main__" :
4851 user_input = input ("Enter numbers separated by a comma:\n " ).strip ()
4952 unsorted = [int (item ) for item in user_input .split ("," )]
50- print (insertion_sort (unsorted ))
53+ print (f" { insertion_sort (unsorted ) = } " )
You can’t perform that action at this time.
0 commit comments