Skip to content

Instantly share code, notes, and snippets.

@mh0w
Created October 21, 2022 15:41
Show Gist options
  • Save mh0w/8e135bc33679b3fa1f4fa4566b0c81eb to your computer and use it in GitHub Desktop.
Save mh0w/8e135bc33679b3fa1f4fa4566b0c81eb to your computer and use it in GitHub Desktop.
random sample from a dictionary (dict)
import random
# Set seed for replicable results
random.seed(3210)
d = {'math': 99, 'english': 80, 'chemistry': 67, 'biology': 88, 'physics': 93}
dict(random.sample(d.items(), 2))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment