def GetLineCount(line_counts, filename):
  """Find the length of a file. Results are cached in the line_counts
  dictionary."""
  if filename in line_counts:
    return line_counts[filename]
  with open(filename, 'r') as f:
    line_count = len(f.readlines())
  line_counts[filename] = line_count
  return line_count