Created
December 9, 2013 14:57
-
-
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().
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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