Creating a posterior distribution for classic coin flipping in python using grid search
In short

The problem assumes a uniform prior distribution function. All possible $P(H)$ are equally likely. Because they are standardizing the probability distribution function at the end it does not matter what value is placed in 

prior=np.repeat(1,grid_points)




Likelihood function

The likelihood function answers the question, how probable is the prior which we assumes.

For example, when flipping a fair coin we can assume that the probability of getting a heads is $P(H) = 0.5$. Now, if we do an experiment and in 3 flips we observe 3 heads then $P(HHH|P(H)=0.5) = 0.5^3$. This tells us that their is only a 0.125 chance that we selected the correct prior. 

$Posterior \propto Likelihood \times Prior$

The code

As you observed it is strange that they set their entire list with the value $5$. However this will have no effect on the results because the before last line standardizes the results. Try changing the $5$ to a different value and you will see that your results remain unchanged. 

Let's go through the code

grid = np.linspace(0, 1, grid_points)


This creates an array between $0$ and $1$. This is the different probabilities we will assume to calculate our likelihood. For example if we use 5 grid_points we have $[0, 0.25, 0.5, 0.75, 1]$. So we will assume that $P(H)$ is equal to these values in turn and get the resulting likelihood for each value. 

likelihood=stats.binom.pmf(heads, tosses, grid)


We can now set out prior however we wish. We can assume that the coin is fair, or we can have no clue and just assume that it's a uniform distribution. This is essentially what they are doing here. The value they chose makes no difference in the results. However, I think for clarity making it equal to 1 is more obvious.

prior=np.repeat(1,grid_points)


To calculate the posterior we multiply the prior by the likelihood

unstd_posterior = likelihood * prior


And then to get a probability distribution function we standardize the function.

posterior = unstd_posterior / unstd_posterior.sum()