def replicate(lst, n):
    """ Replicate each of the elements of lst a given number of times. For example, for lst = [a, b, c] and n = 3, the returned list is [a, a, a, b, b, b, c, c, c]. """
    def rep_helper(val, n):
        i = 0
        v = ""
        while i < n:
            v = v + val
            i += 1
        return v
    list_of_lists = [list(rep_helper(a, n)) for a in lst]
    return [val for sublist in list_of_lists for val in sublist]