import random


def w_choice(seq):
    """
    Takes an input on the form of [('A', 30), ('B', 40), ('C', 30)] and returns
    one of the items based on the probality from the second value in each tuple.
    Eg. B will get chosen 40% of the time while A and C will get chosen 30% of
    the time.
    """
    total_prob = sum(item[1] for item in seq)
    chosen = random.uniform(0, total_prob)
    cumulative = 0
    for item, probality in seq:
        cumulative += probality
        if cumulative > chosen:
            return item