import random


def _sample_map_partitions(population, k):
    """
    Map function used on the sample and choices functions.
    Parameters
    ----------
    population : list
        List of elements to sample.
    k : int, optional
        Number of elements to sample. Default is 1.

    Returns
    -------
    sample : list
        List of sampled elements from the partition.
    lx : int
        Number of elements on the partition.
    k : int
        Number of elements to sample.
    """
    lx = len(population)
    real_k = k if k <= lx else lx
    # because otherwise it raises IndexError:
    sampled = [] if real_k == 0 else random.choices(population, k=real_k)
    return sampled, lx