fork download
  1. from io import StringIO
  2.  
  3. data = StringIO("""\
  4. 0.009 724
  5. 0.426 725
  6. 0.028 726
  7. # #
  8. # #
  9. 0.013 0
  10. 0.258 1
  11. 0.15 2
  12. # #
  13. # #
  14. 0.713 5
  15. 0.145 2
  16. 0.785 0
  17. """)
  18.  
  19. from itertools import groupby
  20. from operator import methodcaller
  21.  
  22. separator = methodcaller('startswith', '#')
  23. #separator = '# #\n'.__eq__
  24.  
  25. lists = (
  26. (tuple(map(float, pair.split())) for pair in line)
  27. for is_sep, line in groupby(data, separator)
  28. if not is_sep
  29. )
  30.  
  31. print(*map(list, lists), sep='\n')
Success #stdin #stdout 0.1s 10104KB
stdin
Standard input is empty
stdout
[(0.009, 724.0), (0.426, 725.0), (0.028, 726.0)]
[(0.013, 0.0), (0.258, 1.0), (0.15, 2.0)]
[(0.713, 5.0), (0.145, 2.0), (0.785, 0.0)]