fork download
  1. from itertools import izip_longest
  2.  
  3. data = "10 30 40 50 60 70"
  4.  
  5. def grouper(iterable, n, fillvalue=None):
  6. "Collect data into fixed-length chunks or blocks"
  7. # grouper('ABCDEFG', 3, 'x') --> ABC DEF Gxx
  8. args = [iter(iterable)] * n
  9. return izip_longest(fillvalue=fillvalue, *args)
  10.  
  11. for x,y in grouper(data.split(" "), 2):
  12. print(x, y)
Success #stdin #stdout 0s 23296KB
stdin
Standard input is empty
stdout
('10', '30')
('40', '50')
('60', '70')