Input
Take a list of values xi each paired with a key yi.
[(x1, y1), (x2, y2), ...]
Output
Return a list L containing only values from the set {xi}.
- The length of L must be equal to the number of unique keys k in the set {yi}.
- For each unique key k there must be a value from {xi} that has key k.
Details
- Standard loopholes disallowed.
- You can assume all values in the input will be nonnegative integers.
- There may be duplicate values and keys.
- You can assume there is at least one value/key pair in the input.
- If you prefer to take two lists of equal length as input (one for values, one for keys) that is fine.
- You may not take any other input.
- The order of the list you output does not matter.
- The xi you choose for each key does not matter.
For example, with input [[0, 0], [1, 3], [2, 3]]
you can return either [0, 1]
or [0, 2]
or any permutation of these.
Examples
[[1, 2], [3, 2], [3, 0]] -> [1, 3] or [3, 3]
[[7, 2], [7, 0], [7, 1]] -> [7, 7, 7]
[[4, 0], [4, 0], [9, 1], [5, 2]] -> [4, 9, 5]
[[9, 1], [99, 10], [5, 5], [0, 3]] -> [9, 99, 5, 0]
Fewest bytes wins.
key value key value key value ...
? \$\endgroup\$key
s? Can we take two arrays askeys
andvalues
as input? Or create our own custom Map that does take multiple values as input (or perhaps a list of key-value pairs)? \$\endgroup\$If you prefer to take two lists of equal length as input that is fine.
Is this what you mean? I don't know what you mean about "Maps". \$\endgroup\$