| def list_chunk(lst, n): return [lst[i:i+n] for i in range(0, len(lst), n)] list_test = list(range(1,30)) print("분할 전 : ", list_test) list_chunked = list_chunk(list_test, 6) print("분할 후 : ", list_chunked) |
# 출력
# 분할 전 : [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30]
# 분할 후 : [[1, 2, 3, 4, 5, 6], [7, 8, 9, 10, 11, 12], [13, 14, 15, 16, 17, 18], [19, 20, 21 22, 23, 24], [25, 26, 27, 28 29, 30],[31]]
'SW > Python' 카테고리의 다른 글
| [python] json파일 다루기 (0) | 2023.11.02 |
|---|