def WeightedSelectionWithoutReplacement(l, n):
    """Selects without replacement n random elements from a list of (weight, item) tuples."""
l = sorted((random.random() * x[0], x[1]) for x in l)
Weighted random selection with and without replacement