def calculate_percentages(counts):
    """
    Given a list of (token, count) tuples, create a new list (token,
    count, percentage) where percentage is the percentage number of
    occurrences of this token compared to the total number of tokens.

    Arguments:
        counts (list of (str or unicode, int)): tuples of form (token,
        count).
    Arguments:
        list of (str or unicode, int, double): tuples of form (token,
        count, percentage).
    """
    total = 0
    for count in counts:
        assert count[1] >= 0
        total += count[1]
    tuples = [(token, count, (float(count) / total) * 100.0)
              for (token, count) in counts]
    return tuples