import random


def choose(population, weights=None, k=None):
    """
    Chooses k times from the given population with an optional weighted probability.

    :param population: the population to chose from
    :param weights: the weights attached to each population element
    :param k: the amount of times to chose
    :return: an element of the list if k = None, or a k-sized list of choices
    """
    choice = random.choices(population, weights=weights, k=k or 1)
    return choice if k else choice[0]