Passed
Push — master ( 6c5783...76b398 )
by Ken M.
02:37
created

sort_by_removing   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 22
dl 0
loc 29
rs 10
c 0
b 0
f 0
wmc 4

2 Functions

Rating   Name   Duplication   Size   Complexity  
A sort_list() 0 9 3
A sort_by_removing() 0 2 1
1
def sort_list(values: list) -> list:
2
    if len(values) in [0, 1]:
3
        return values
4
    if values[0] <= values[1]:
5
        return [values[0]] + sort_list(values[1:])
6
    else:
7
        values_copy = values[:]
8
        values_copy.remove(values[1])
9
        return sort_list(values_copy)
10
11
12
def sort_by_removing(values: list) -> list:
13
    return sort_list(values)
14
15
16
if __name__ == '__main__':
17
    print("Example:")
18
    print(sort_by_removing([3, 5, 2, 6]))
19
20
    # These "asserts" are used for self-checking and not for an auto-testing
21
    assert sort_by_removing([3, 5, 2, 6]) == [3, 5, 6]
22
    assert sort_by_removing([7, 6, 5, 4, 3, 2, 1]) == [7]
23
    assert sort_by_removing([3, 3, 3, 3]) == [3, 3, 3, 3]
24
    assert sort_by_removing([5, 6, 7, 0, 7, 0, 10]) == [5, 6, 7, 7, 10]
25
    assert sort_by_removing([1, 5, 2, 3, 4, 7, 8]) == [1, 5, 7, 8]
26
    assert sort_by_removing([1, 7, 2, 3, 4, 5]) == [1, 7]
27
    assert sort_by_removing([]) == []
28
    print("Coding complete? Click 'Check' to earn cool rewards!")
29