def iterate_pagerank(corpus, damping_factor):
    """
    Return PageRank values for each page by iteratively updating
    PageRank values until convergence.

    Return a dictionary where keys are page names, and values are
    their estimated PageRank value (a value between 0 and 1). All
    PageRank values should sum to 1.
    """
    distribution = dict()
    corpus_length = len(corpus)
    for u in corpus: #On first iteration, each page is equally likely.
        distribution[u] = 1.0 / corpus_length

    difference = 1.0
    max_difference = 0.0
    while ( difference > 0.001 ):
        old_distribution = distribution.copy()
        for u in corpus: #Page we are currently looking at
            prob = (1.0 - damping_factor) / corpus_length
            for x in corpus:
                if u == x:
                    continue
                if u in corpus[x]:
                    links = list(corpus[x])
                    prob += damping_factor * (distribution[x] / len(links))
            distribution[u] = prob
            difference = abs(distribution[u] - old_distribution[u])
            if difference > max_difference: max_difference = difference
    return distribution