def readMetadata(lines):
   """
   Read metadata tags and values from a TNTP file, returning a dictionary whose
   keys are the tags (strings between the <> characters) and corresponding values.
   The last metadata line (reading <END OF METADATA>) is stored with a value giving
   the line number this tag was found in.  You can use this to proceed with reading
   the rest of the file after the metadata.
   """
   metadata = dict()
   lineNumber = 0
   for line in lines:
      lineNumber += 1
      line.strip()
      commentPos = line.find("~")
      if commentPos >= 0: # strip comments
         line = line[:commentPos]
      if len(line) == 0:
         continue

      startTagPos = line.find("<")
      endTagPos = line.find(">")
      if startTagPos < 0 or endTagPos < 0 or startTagPos >= endTagPos:
         print("Error reading this metadata line, ignoring: '%s'" % line)
      metadataTag = line[startTagPos+1 : endTagPos]
      metadataValue = line[endTagPos+1:]
      if metadataTag == 'END OF METADATA':
         metadata['END OF METADATA'] = lineNumber
         return metadata
      metadata[metadataTag] = metadataValue.strip()
      
   print("Warning: END OF METADATA not found in file")
   return metadata