Skip to content

Instantly share code, notes, and snippets.

@yuizumi
Created December 9, 2013 14:57
Show Gist options
  • Save yuizumi/7873488 to your computer and use it in GitHub Desktop.
Save yuizumi/7873488 to your computer and use it in GitHub Desktop.
A poor-man's Scanner in Python, provided as a function that takes a file object and returns an iterator whose next() works like Java's Scanner.next().
def EasyScanner(reader):
return (word for line in reader for word in line.split())
# License: CC0 1.0 Universal
# http://creativecommons.org/publicdomain/zero/1.0/
sc = EasyScanner(sys.stdin)
s = sc.next() # Like Scanner.next().
i = int(sc.next()) # Like Scanner.nextInt().
f = float(sc.next()) # Like Scanner.nextDouble().
# For a real example, see: http://arc015.contest.atcoder.jp/submissions/121667.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment