Problem: py.checkio.org/en/mission/split-list/
My solution
python
접기def split_list(items: list) -> list: # your code here length = len(items) if length % 2 == 0: return [items[:length//2],items[length//2:]] else: return [items[:length//2+1],items[length//2+1:]] if __name__ == '__main__': print("Example:") print(split_list([1, 2, 3, 4, 5, 6])) # These "asserts" are used for self-checking and not for an auto-testing assert split_list([1, 2, 3, 4, 5, 6]) == [[1, 2, 3], [4, 5, 6]] assert split_list([1, 2, 3]) == [[1, 2], [3]] assert split_list([1, 2, 3, 4, 5]) == [[1, 2, 3], [4, 5]] assert split_list([1]) == [[1], []] assert split_list([]) == [[], []] print("Coding complete? Click 'Check' to earn cool rewards!")
A good solution that I see
python
접기def split_list(items: list) -> list: return [items[:(split_index := (len(items) + 1) // 2)], items[split_index:]]
'프로그래밍 문제 > [Python] CheckIO' 카테고리의 다른 글
[Check-IO] Morse Decoder (0) | 2021.03.08 |
---|---|
[CheckIO] Solve All the same (0) | 2021.01.07 |
[CheckIO] Sun angle (0) | 2021.01.03 |
[CheckIO] pawn-brotherhood (0) | 2021.01.02 |
[CheckIO] sort array by element frequency (0) | 2020.12.30 |
댓글