Last active
August 29, 2015 14:15
-
-
Save mikejoyceio/5e31d34c647b6ceef5fc to your computer and use it in GitHub Desktop.
Python function that returns a specified number of random items from an iterable
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
def random_items(itr, int): | |
list = [] | |
count = 0 | |
while count < int: | |
rand = random.choice(itr) | |
list.append(rand) | |
count += 1 | |
return list |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment