File tree 1 file changed +10
-7
lines changed
1 file changed +10
-7
lines changed Original file line number Diff line number Diff line change 1
1
"""
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.
3
8
4
9
For doctests run following command:
5
- python -m doctest -v insertion_sort.py
6
- or
7
10
python3 -m doctest -v insertion_sort.py
8
11
9
12
For manual testing run:
10
- python insertion_sort.py
13
+ python3 insertion_sort.py
11
14
"""
12
15
13
16
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
16
19
17
20
:param collection: some mutable ordered collection with heterogeneous
18
21
comparable items inside
@@ -47,4 +50,4 @@ def insertion_sort(collection):
47
50
if __name__ == "__main__" :
48
51
user_input = input ("Enter numbers separated by a comma:\n " ).strip ()
49
52
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