2
2
Gnome Sort Algorithm (A.K.A. Stupid Sort)
3
3
4
4
This algorithm iterates over a list comparing an element with the previous one.
5
- If order is not respected, it swaps element backward until
6
- order is respected with previous element.
7
- It resumes the initial iteration from element new position.
5
+ If order is not respected, it swaps element backward until order is respected with
6
+ previous element. It resumes the initial iteration from element new position.
8
7
9
8
For doctests run following command:
10
9
python3 -m doctest -v gnome_sort.py
@@ -18,9 +17,8 @@ def gnome_sort(lst: list) -> list:
18
17
"""
19
18
Pure implementation of the gnome sort algorithm in Python
20
19
21
- Take some mutable ordered collection with heterogeneous
22
- comparable items inside as argument,
23
- return the same collection ordered by ascending.
20
+ Take some mutable ordered collection with heterogeneous comparable items inside as
21
+ arguments, return the same collection ordered by ascending.
24
22
25
23
Examples:
26
24
>>> gnome_sort([0, 5, 3, 2, 2])
@@ -31,6 +29,9 @@ def gnome_sort(lst: list) -> list:
31
29
32
30
>>> gnome_sort([-2, -5, -45])
33
31
[-45, -5, -2]
32
+
33
+ >>> "".join(gnome_sort(list(set("Gnomes are stupid!"))))
34
+ ' !Gadeimnoprstu'
34
35
"""
35
36
if len (lst ) <= 1 :
36
37
return lst
0 commit comments