Skip to content

Instantly share code, notes, and snippets.

@jweinst1
Last active September 24, 2015 07:57
Show Gist options
  • Save jweinst1/c43a2a59300f1a50200d to your computer and use it in GitHub Desktop.
Save jweinst1/c43a2a59300f1a50200d to your computer and use it in GitHub Desktop.
probability toolkit.py
#prob function toolkit
from decimal import *
#takes a decimal probability
def chance(choose, total):
getcontext().prec = 6
return float(Decimal(choose)/Decimal(total))
#checks probability of choosing elem from a lst.
def occurence(elem, lst):
getcontext().prec = 6
size = lst.count(elem)
return chance(size, len(lst))
def get_chances(lst):
return {x:occurence(x, lst) for x in lst}
def best_chance(lst):
dict = {occurence(x, lst):x for x in lst}
return dict[max(dict.keys())]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment