Created
February 17, 2018 19:09
-
-
Save tbnbooij/14d87d86cc88fcde059d726395ee681c to your computer and use it in GitHub Desktop.
A small python script to speed up input reading at programming competitions.
This file contains 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
class Reader: | |
def __init__(self, path): | |
self.contents = open(path, 'r').read().split("\n") | |
def readList(self, line_index): | |
return list(map(int, self.contents[line_index].split(" "))) | |
def readInt(self, line_index): | |
return int(self.contents[line_index]) | |
def readGroup(self, line_index, length_pattern): | |
return_list = [] | |
for i in range(length_pattern): | |
return_list.append(self.readList(line_index + i)) | |
return return_list | |
def readRepeatingGroup(self, line_index, length_pattern, iterations): | |
return_list = [] | |
for i in range(iterations): | |
self.readGroup(line_index + length_pattern*i, length_pattern) | |
return return_list |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment