This question already has answers here:
How do you split a list into evenly sized chunks?
(60个答案)
Iterate an iterator by chunks (of n) in Python? [duplicate]
(9个答案)
如果我有一个列表:
如何遍历它以便输出以下内容:
(60个答案)
Iterate an iterator by chunks (of n) in Python? [duplicate]
(9个答案)
如果我有一个列表:
["A","Bb","C","D","E","F","G"]
如何遍历它以便输出以下内容:
"A Bb C"
"D E F"
"G"
最佳答案
是一个我一直在找的食谱。
def chunks(l, n):
for i in xrange(0, len(l), n):
yield l[i:i+n]
10-06 01:01