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])
Written by Jeremiah Malina
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Python
Authors
Related Tags
#python
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#