Passed
Push — master ( 76b398...791de7 )
by Ken M.
01:38
created

split_list.split_list()   A

Complexity

Conditions 2

Size

Total Lines 6
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
nop 1
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
def split_list(items: list) -> list:
2
    length = len(items)
3
    if length % 2:
4
        return [items[:length // 2 + 1], items[length // 2 + 1:]]
5
    else:
6
        return [items[:length // 2], items[length // 2:]]
7
8
9
if __name__ == '__main__':
10
    print("Example:")
11
    print(split_list([1, 2, 3, 4, 5, 6]))
12
13
    # These "asserts" are used for self-checking and not for an auto-testing
14
    assert split_list([1, 2, 3, 4, 5, 6]) == [[1, 2, 3], [4, 5, 6]]
15
    assert split_list([1, 2, 3]) == [[1, 2], [3]]
16
    assert split_list([1, 2, 3, 4, 5]) == [[1, 2, 3], [4, 5]]
17
    assert split_list([1]) == [[1], []]
18
    assert split_list([]) == [[], []]
19
    print("Coding complete? Click 'Check' to earn cool rewards!")
20