Created
October 1, 2013 08:41
-
-
Save aaronsaunders/6775537 to your computer and use it in GitHub Desktop.
Get random sample from list while maintaining ordering of items? I have a sorted list, let say: (its not really just numbers, its a list of objects that are sorted with a complicated time consuming algorithm) mylist = [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 ,9 , 10 ] Is there some python function that will give me N of the items, but will keep the order…
This file contains 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
# Following code will generate a random sample of size 4. | |
rand_smpl = [ mylist[i] for i in sorted(random.sample(xrange(len(mylist)), 4)) ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment