def partition_all(n, seq):
 args = ([iter(seq)] * n)
 it = zip_longest(fillvalue=no_pad, *args)
 prev = next(it)
 for item in it:
  (yield prev)
  prev = item
 if (prev[(-1)] is no_pad):
  (yield prev[:prev.index(no_pad)])
 else:
  (yield prev)

def partition_all ( n , seq ) : args = ( [ iter ( seq ) ] * n ) it = zip_longest ( fillvalue = no_pad , * args ) prev = next ( it ) for item in it : ( yield prev ) prev = item if ( prev [ ( - 1 ) ] is no_pad ) : ( yield prev [ : prev . index ( no_pad ) ] ) else : ( yield prev )
partition all elements of sequence into tuples of length at most n the final tuple may be shorter to accommodate extra elements .