Guest User

Untitled

a guest
Jan 23rd, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. import random
  2. from collections import Counter
  3.  
  4. items = ['dog', 'cat', 'bird', 'plane', 'circus', 'turtle', 'oven', 'food', 'running', 'hello']
  5. weights=[10, 20, 35, 5, 18, 3, 19, 4, 5, 12]
  6.  
  7. pop_counter = Counter(random.choices(items, weights=weights, k=100000)).most_common(10) # Our population
  8.  
  9. # Get the populatino into a list
  10. population = []
  11.  
  12. for item, count in pop_counter:
  13. population.extend([item] * count)
  14.  
  15. assert(len(population) == 100000)
  16.  
  17. # Print out the %'s
  18. for item, count in pop_counter:
  19. print(item, count/100000)
  20.  
  21. bird 0.26634
  22. cat 0.15414
  23. oven 0.14347
  24. circus 0.13777
  25. hello 0.09207
  26. dog 0.07775
  27. plane 0.03826
  28. running 0.03777
  29. food 0.03081
  30. turtle 0.02162
  31.  
  32. for item, count in Counter(random.sample(population=population, k=400)).most_common():
  33. print(item, count/400)
  34.  
  35. bird 0.2425
  36. circus 0.165
  37. cat 0.155
  38. oven 0.1475
  39. hello 0.105
  40. dog 0.0875
  41. running 0.035
  42. food 0.0325
  43. plane 0.0175
  44. turtle 0.0125
Add Comment
Please, Sign In to add comment