def transition_model(corpus, page, damping_factor):
    """
    Return a probability distribution over which page to visit next,
    given a current page.

    With probability `damping_factor`, choose a link at random
    linked to by `page`. With probability `1 - damping_factor`, choose
    a link at random chosen from all pages in the corpus.
    """
    # If page has at least one outgoing link
    if corpus[page]:
        # Initialise probability distribution to P(page chosen at random out of all pages in corpus)
        total_probabilities = [(1 - damping_factor) / len(corpus)] * len(corpus)
        total_probabilities_dict = dict(zip(corpus.keys(), total_probabilities))

        # Add additional probability for all pages linked to by current page
        link_probabilities = damping_factor / len(corpus[page])
        for link in corpus[page]:
            total_probabilities_dict[link] += link_probabilities
        return total_probabilities_dict

    # If page has no outgoing links, probability distribution chooses randomly among all pages with equal probability
    else:
        return dict(zip(corpus.keys(), [1 / len(corpus)] * len(corpus)))