<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def mod_categorical_expval(p):
 """ Expected value of categorical distribution with parent p of length k-1. An implicit k'th category is assumed to exist with associated probability 1-sum(p). """

    p = extend_dirichlet(p)
    return np.sum([p * i for i, p in enumerate(p)])