可能重复:
How do you split a list into evenly sized chunks in Python?HOWTO迭代超过一个元素在Python的for循环
的想法很简单,我希望做这样的事情:
for elem1, elem2, elem3 in list:
<some code>
为了这个工作,我们需要该列表将是一个3-iterables列表,如下所示:
list = [[1, 2, 3], [4, 5, 6]]
但是,如果此列表只是一个常规列表,该怎么办?
list = [1, 2, 3, 4, 5, 6]
有没有改变这个规则列表进入3 iterables列表,以便循环将工作中的任何快速简单的方式?或者n-iterables,我只是在这里用3作为例子。
谢谢。
像这样:http://stackoverflow.com/questions/312443/how-do-you-split -a-list-into-uniformity-sized-chunks-in-python? – georg
好的谢谢,对不起,如果我有同样的问题,我试图搜索之前问,但我没有发现任何东西 – Ole