Adding elements to dict

Similar to lists or sets, we can define empty dictionaries and then add elements gradually:
# Let's count the number of candies little Stan ate
candies = {}
candies['Kinder'] = 4
candies['Haribo'] = 10
candies['Raffaello'] = 1
print(candies)
# {'Kinder': 4, 'Haribo': 10, 'Raffaello': 1}
We can also modify the values for some keys. We can treat values as ordinary variables and perform operations as we would perform them on variables (assign, add, subtract, etc):
candies = {}
candies['Kinder'] = 4
candies['Haribo'] = 10
candies['Raffaello'] = 1

# And then he ate another Kinder
candies['Kinder'] = 5

# And then he ate another Raffaello
candies['Raffaello'] += 1

print(candies)
# {'Kinder': 5, 'Haribo': 10, 'Raffaello': 2}

Challenge

The HR (Human Resources) department is struggling to keep track of the company's positions and the people who hold those positions. They would be very grateful if you could help them keep track of that list. For each of the n positions, there is a single person they hired lately. Now they have q questions. For each question, they ask you the position, and you are asked to tell them the name of the person that they hired for that position.
The first line of the input contains a single integer n - the number of hires the HR department has made. The next n lines contain first the position of that person followed by the name. The next line contains a single integer q - the number of questions. The following q lines contain positions for which you are asked to print the corresponding person’s name.
The program should print q lines. Each line should contain the name of the person that was hired for the position in the question.
Input
Output
5 Accountant Mike Finances Lucy COO Anna IT Bob Accountant Sophie 2 IT Accountant
Bob Sophie
Note: They fired the Accountant Mike and hired Sophie for that position.
 

Constraints

Time limit: 2 seconds

Memory limit: 512 MB

Output limit: 1 MB

To check your solution you need to sign in
Sign in to continue