Wednesday, November 5, 2008

99 problems - python - 23

Extract a given number of randomly selected elements from a list.

import random
def random_select(lst, n):
for x in range(n):
yield random.choice(lst)

Depending on how you interpret the problem you may just want to use random.sample

No comments: