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.
    """
    damping_prob = 1 / len(corpus)
    if len(corpus[page]) == 0:  # If page has no links, all pages have equal prob
        distribution = {ipage: damping_prob for ipage in corpus}
    else:
        linked_prob = 1 / len(corpus[page])
        distribution = {ipage: damping_prob * (1 - damping_factor) for ipage in corpus}
        for ipage in corpus[page]:  # Add links probabilities
            distribution[ipage] += damping_factor * linked_prob


    return distribution