def process_training_data(self_play_data, replay_length=None):
    """Takes self play data and returns a list of tuples (state,
    action_probs, utility) suitable for training an estimator.

    Parameters
    ----------
    self_play_data: dict
        Dictionary with keys given by an index (int) and values given by a
        log of the game. This is a list of tuples as in generate self play
        data.
    replay_length: int or None
        If given, only return the last replay_length (state, probs, utility)
        tuples.
    """
    training_data = []
    for index, game_log in self_play_data.items():
        for (state, action, probs_vector, z) in game_log:
            training_data.append((state, probs_vector, z))
    
    print("Training data length: {}".format(len(training_data)))
    print("Self play data length: {}".format(len(self_play_data)))

    if replay_length is not None:
        training_data = training_data[-replay_length:]

    return training_data