-
list 나눠서 출력Python/기초 2021. 10. 20. 15:57
#10개씩 출력
for i in range(0, len(Cube_Finded), 10):
print(Cube_Finded[i:i+10])
# n개씩 출력
def list_chunk(lst, n):
return [lst[i:i+n] for i in range(0, len(lst), n)]
list_test = list(range(1,32))
print("분할 전 : ", list_test)
list_chunked = list_chunk(list_test, 7)
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, 31]
# 후 : [[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]]출처: https://jsikim1.tistory.com/141
Python list chunk - 리스트 분할(자르기, 나누기, split) 방법
Python list chunk - 리스트(배열) 분할(자르기, 나누기, split) 방법 Python에서 list를 원하는 간격으로 나누는 방법을 알려드리도록 하겠습니다. PHP에서는 array_chunk() 를 사용하여 배열을 원하는..
jsikim1.tistory.com
728x90'Python > 기초' 카테고리의 다른 글
(python) self 를 인자로 받는 함수와 그렇지 않은 함수 (0) 2021.12.01 int.from_bytes python (0) 2021.10.22 python main함수 변수 (0) 2021.10.20 zip() 함수 (0) 2021.10.19 메모리 주소값 불러오는 함수 id() (0) 2021.10.18 댓글