Weighted Sampling

Hard
statistics Citadel Two Sigma Goldman Sachs

Given a list of items and their weights, compute the probability of each item being selected in a weighted random sample. Return a dictionary mapping each item to its probability (as a float).

Example

sampling_probs(["a", "b", "c"], [1, 2, 7])
# => {"a": 0.1, "b": 0.2, "c": 0.7}

Test Cases

Python Editor

Output

Click "Run" to see results...