All problems

The Key-Value Join

hardPythonData CleaningDictionaries

Ravenscroft College holds student names in one export and exam scores in another, and the two files have nothing in common but the student id. The results sheet lists every score with the student's name beside it, in the order the scores were entered, because that is the order the invigilator worked through the hall. Some ids in the score file have no matching name — students who enrolled after the name export was taken — and those still need their line on the sheet.

Task: Print each score with its student's name.

Input

Four parts. The first line holds one integer n, how many name rows follow. Each of the next n lines holds a student id and a name, separated by a single space. The line after those holds one integer m, how many score rows follow. Each of the next m lines holds a student id and a score, separated by a single space. Ids are single words matched exactly. A name may have no score, and a score may have no name.

Output

m lines, one per score row, in the order the score rows appeared. Each line holds the student's name, one space, then the score exactly as it was written. Where an id has no matching name, print unknown in place of the name.

Example:

Input:
2
1 ana
2 ben
3
2 90
1 85
9 70

Output:
ben 90
ana 85
unknown 70

Sign in to solve this problem

Reading problems is free for everyone — solving them (Run, Submit, and tracking what you've solved) needs an account.

Sign in

Discussion

Sign in to join the discussion — reading is open to everyone.

Loading comments…