Last Updated: February 25, 2016
·
440
· jmalina327

Randomly sample a random number of items from a list

from random import shuffle, sample


def randomly_sample_list(list):
    """
    Randomly samples a random number of elements from a list
    """
    shuffle(list)
    return sample(list, sample(xrange(len(list) + 1), 1)[0])