18 Exactly three heads in five flips#

%%html
<iframe width="700" height="400" src="https://www.youtube.com/embed/udG9KhNMKJw/" frameborder="0" allowfullscreen></iframe>
import itertools
import numpy as np
import pandas as pd
from pandas import Series, DataFrame
import matplotlib.pyplot as plt
import seaborn as sns
from scipy import stats, special

khanacademy

Exactly three heads in five flips fig 1

def P(cond, total_lst):
    cond_lst = list(filter(cond, total_lst))
    return len(cond_lst) / len(total_lst), cond_lst
flips = ["".join(i) for i in itertools.product(['H', 'T'], repeat=5)]
p, _ = P(lambda x: x.replace('T', '') == 'HHH', flips)
p
0.3125
special.comb(5, 3) / len(flips)
0.3125