def split_every(n, iterable, piece_maker=tuple):
 iterator = iter(iterable)
 piece = piece_maker(islice(iterator, n))
 while piece:
  (yield piece)
  piece = piece_maker(islice(iterator, n))

def split_every ( n , iterable , piece_maker = tuple ) : iterator = iter ( iterable ) piece = piece_maker ( islice ( iterator , n ) ) while piece : ( yield piece ) piece = piece_maker ( islice ( iterator , n ) )
splits an iterable into length-n pieces .