#NEWLINE# def chunked( seq , n ) : #NEWLINE# #INDENT# 'By Ned Batchelder.\n    Yield successive n-sized chunks from seq.\n\n    >>> for group in chunked(range(8), 3):\n    ...     print group\n    [0, 1, 2]\n    [3, 4, 5]\n    [6, 7]\n    ' #NEWLINE# for i in xrange ( 0 , len ( seq ) , n ) : #NEWLINE# #INDENT# ( yield seq [ i : ( i + n ) ] )