def value_of(mdp, s, a, v, gamma):
    """
    Compute the value of taking action `a` in state `s` in `mdp` with respect existing values in `v`.

    Should, given state $s$, action $a$, and discount factor $\gamma$ compute 
    $\sum_{s' \in S} P(s,a,s') * ( R(s,a,s') + \gamma * v(s') )$
    where $S$ is the set of successor states to $s$ and $a$.

    Parameters
    ----------
    mdp : mdp.MDP
    s : state
    a : action
    v  : dict of state : float
       value of states at time t - 1
    gamma : float in ]0,1[

    Returns
    -------
    float
       New value.
    """

    # -------- TASK 2.1 --------------------------------------------------------
    # TASK: Implement the function computing the sum described above and return
    # the value as a float. Look at the documentation for mdp.MDP to see how
    # the rewards R and probabilities P can be retrieved.
    #
    # CODE HERE CODE HERE CODE HERE
    ss = mdp.successor_states(s, a)
    new_v = 0.0
    for s2 in ss:
        new_v += mdp.P(s, a, s2) * (mdp.R(s, a, s2) + gamma * v[s2])
    return new_v