import random


def sample_independently(L,p):
    """
    Return a sample of the given list of precincts, sampled according to p.
        L = input list of precincts, 0<=i<n; each is (size,name) pair.
        p = input list of their probabilities.
    Select precincts with probability proportional to probabilities in p.
    Each precinct is selected *independently*.
    """
    n = len(L)
    sample = []
    for i in range(n):
        if random.random() <= p[i]:
            sample.append(L[i])
    return sample