fork download
  1. #!/usr/bin/env python
  2. import sys
  3. from functools import partial
  4. from itertools import takewhile
  5.  
  6. def get_tokens(stream=sys.stdin):
  7. token = []
  8. for char in iter(partial(stream.read, 1), ''):
  9. if char.isspace(): # use any space as a separator
  10. yield ''.join(token)
  11. del token[:]
  12. else:
  13. token.append(char)
  14. if token:
  15. yield ''.join(token)
  16.  
  17. print(' '.join(takewhile(lambda s: s != '-1', get_tokens())))
  18.  
  19.  
Success #stdin #stdout 0.03s 9072KB
stdin
12 22 -23 13 -12 23 -1 23 12 22 -23 3 -1 23 -1 23 12 22 -23 3 -1 23 -1 23 12 22 -23 3 -1 23 -1 23
12 22 -23 3 -1 23 -1 23 12 22 -23 3 -1 23 -1 23 12 22 -23 3 -1 23 -1 23 12 22 -23 3 -1 23 -1 23 12 22 -23 3 -1 23 -1 23 12 22 -23 3 -1 23 -1 23 12 22 -23 3 -1 23 -1 23 12 22 -23 3 -1 23 -1 23 12 22 -23 3 -1 23 -1 23 12 22 -23 3 -1 23 -1 23 12 22 -23 3 -1 23 -1 23
stdout
12 22 -23 13 -12 23