def sample(iterable, n_sample):
    """
     Produce a random sample from the list. Pass a number to return n random elements from the list. Otherwise a single random item will be returned. 

    CAUTION: Does not yet work with generators
    params: iterable, n_sample
        iterable -> list, sequenece, set, dictionary
        n_sample -> number of random samples to be taken from iterable

    TODO: implement walker's method. current one is too inefficient
    http://code.activestate.com/recipes/576564-walkers-alias-method-for-random-objects-with-diffe/
    Examples:
    >>> _.sample([1, 2, 3, 4, 5, 6])
    >>> [4]
    >>> _.sample([1, 2, 3, 4, 5, 6], 3)
    >>> [1, 6, 2]
    """
    try:
        length = len(iterable)
    except TypeError:
        raise TypeError('sample does not work well with generators')
    import random
    sampled = []
    iterable = list(iterable)
    for i in range(n_sample):
        chosen = random.choice(iterable)
        iterable.remove(chosen)
        sampled.append(chosen)
    return sampled
