def replication(samples):
    """
    Deterministically replicate samples.

    :param samples: A list in which each element again is a list containing the sample
    and the number of times the sample needs to be replicated, e.g.:
      samples = [(x1, 2), (x2, 0), ..., (xM, 1)]
    :return: list of replicated samples: [x1, x1, ..., xM]
    """

    # A perhaps more understandable way to solve this could be:
    # replicated_samples = []

    # for m in range(1, len(samples)+1):
    #     xk, Nk = samples[m-1]
    #     for unused in range(1, Nk+1):
    #         replicated_samples.append(xk)
    # return replicated_samples

    # Same result: repeat each state (denoted by s[0]) Nk times (denoted by s[1])
    return [l for s in samples for l in s[1] * [s[0]]]