Skip to content

Instantly share code, notes, and snippets.

@krdlab
Last active February 22, 2019 08:52
Show Gist options
  • Save krdlab/84fba0dad30c9c68c49289089b053154 to your computer and use it in GitHub Desktop.
Save krdlab/84fba0dad30c9c68c49289089b053154 to your computer and use it in GitHub Desktop.
Python のリストを N 個の塊に分割する
# もっと簡単にできないかな?
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