Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- from collections import Counter
- items = ['dog', 'cat', 'bird', 'plane', 'circus', 'turtle', 'oven', 'food', 'running', 'hello']
- weights=[10, 20, 35, 5, 18, 3, 19, 4, 5, 12]
- pop_counter = Counter(random.choices(items, weights=weights, k=100000)).most_common(10) # Our population
- # Get the populatino into a list
- population = []
- for item, count in pop_counter:
- population.extend([item] * count)
- assert(len(population) == 100000)
- # Print out the %'s
- for item, count in pop_counter:
- print(item, count/100000)
- bird 0.26634
- cat 0.15414
- oven 0.14347
- circus 0.13777
- hello 0.09207
- dog 0.07775
- plane 0.03826
- running 0.03777
- food 0.03081
- turtle 0.02162
- for item, count in Counter(random.sample(population=population, k=400)).most_common():
- print(item, count/400)
- bird 0.2425
- circus 0.165
- cat 0.155
- oven 0.1475
- hello 0.105
- dog 0.0875
- running 0.035
- food 0.0325
- plane 0.0175
- turtle 0.0125
Add Comment
Please, Sign In to add comment