#C13394. CSV Column Maximum Extraction

    ID: 42927 Type: Default 1000ms 256MiB

CSV Column Maximum Extraction

CSV Column Maximum Extraction

You are given the contents of a CSV file via standard input. The first line contains the CSV header with comma‐separated column names. The second line contains an integer N which denotes the number of data rows that follow. Each of the next N lines contains a CSV row with values corresponding to the header. After that, an integer Q is given, followed by Q lines, each containing the name of a column for which you need to compute the maximum value.

Your task is to output a dictionary (in a specific string representation) where each key is one of the queried column names and its value is the maximum numeric value found in that column. If no data rows exist for a column, output None (literal, without quotes) as its value.

If a queried column does not exist in the CSV header, you must output an error message exactly in the following format:

( KeyError: Column {col} does not exist in the CSV file )

Note: All numeric values in the CSV are guaranteed to be convertible to floats. The output dictionary should be printed in one line with keys in double quotes, a colon and a space separating keys and values, and pairs separated by a comma and a space. For example:

{"value1": 20, "value2": 30}

inputFormat

The input is provided via standard input (stdin) and is structured as follows:

  1. A single line with the CSV header (a comma-separated list of column names).
  2. A line with an integer N, representing the number of data rows.
  3. N lines, each being a CSV row corresponding to the header.
  4. A line with an integer Q, the number of query columns.
  5. Q lines, each containing a column name to query.

All input should be read from stdin.

outputFormat

If all queried columns exist in the CSV header, output a dictionary (as a single line) with each queried column as a key and its maximum value (as a number) as the value. If a column has no data rows, its value should be None (literal, without quotes).

If any queried column does not exist in the CSV header, output an error message in the exact format:

KeyError: Column {col} does not exist in the CSV file

Output must be printed to stdout.

## sample
id,value1,value2
3
1,10,20
2,15,25
3,20,30
2
value1
value2
{"value1": 20, "value2": 30}