faqts : Computers : Programming : Languages : Python : Common Problems : Lists

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

2 of 2 people (100%) answered Yes
Recently 2 of 2 people (100%) answered Yes

Entry

How do I loop through a list 4 sequential objects at a time?

May 10th, 2006 15:12
stephen brown, Guest,


You mean like this?
>>> a = range(13)
>>> for b in [a[x:x+4] for x in range(0, len(a), 4)]:
	print b
[0, 1, 2, 3]
[4, 5, 6, 7]
[8, 9, 10, 11]
[12]
>>>