Skip to content

Instantly share code, notes, and snippets.

@tbnbooij
Created February 17, 2018 19:09
Show Gist options
  • Save tbnbooij/14d87d86cc88fcde059d726395ee681c to your computer and use it in GitHub Desktop.
Save tbnbooij/14d87d86cc88fcde059d726395ee681c to your computer and use it in GitHub Desktop.
A small python script to speed up input reading at programming competitions.
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