Last active
February 22, 2019 08:52
-
-
Save krdlab/84fba0dad30c9c68c49289089b053154 to your computer and use it in GitHub Desktop.
Python のリストを N 個の塊に分割する
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# もっと簡単にできないかな? | |
import math | |
N = 10 | |
arr = [1] * 22 | |
parts = [arr[(i*N):((i+1)*N)] for i in range(0, int(math.ceil(len(arr)/float(N))))] | |
for part in parts: | |
print(part) | |
# 出力 | |
# [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] | |
# [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] | |
# [1, 1] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment