All problems

One-Hot Encoding a Batch

easyPythonFeature Engineering

One customer was the rehearsal; now Quillon Energy has to convert the whole tariff column. The slot order comes from the tariff list and from nothing else -- not from which tariffs happen to turn up in this batch, not from alphabetical order, and not from the order they were first seen. Every customer row produces its own line of slots, including customers on a tariff a previous row already used, because the file must come out with exactly as many rows as it went in with.

Task: Print the one-hot slots for every customer in the batch.

Input

The first line holds one integer k, the number of tariffs. The second line holds the k tariff names in their fixed slot order, separated by single spaces. The line after those holds one integer n, the number of customers. Each of the next n lines holds one customer's tariff, always one of the k names.

Output

n lines, one per customer, in the order the customers arrived. Each holds k values separated by single spaces, each either 0 or 1.

Example:

Input:
3
red green blue
2
green
red

Output:
0 1 0
1 0 0

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…