Skip to content

Instantly share code, notes, and snippets.

@yellowsnow
Last active June 8, 2016 13:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yellowsnow/c333cbf48bac3f77cc50e5e078fcbab5 to your computer and use it in GitHub Desktop.
Save yellowsnow/c333cbf48bac3f77cc50e5e078fcbab5 to your computer and use it in GitHub Desktop.
weighted_choices = [('Red', 3), ('Blue', 2), ('Yellow', 1), ('Green', 4)]
population = [val for val, cnt in weighted_choices for i in range(cnt)]
random.choice(population)
villes_avec_poids = [('Tanger', 3), ('Oujda', 2), ('Boujdour', 1), ('Tinghir', 4)]
possibilites = [val for val, cnt in villes_avec_poids for i in range(cnt)]
ville = random.choice(possibilites)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment