def _create_neighbor_dict(codons):
    """
    Create minimum neighbor distances for each amino acid given the genetic
    code.

    Parameters
    ----------
    codons : dict
        dictionary mapping codons to single-letter amino acid codes

    Returns
    -------
    neighbor_dict : dict
        dictionary mapping all possible amino acid pairs (i,j) and (j,i) to
        their minium base pair difference. keys are tuples (e.g. ("A","V"),
        ("Q","R"); values are ints.
    """

    neighbor_dict = {}
    codon_list = list(codons.keys())
    for i in range(len(codon_list)):
        a = codon_list[i]
        for j in range(i,len(codon_list)):
            b = codon_list[j]

            # Count number of base-pair differences between these two
            dist = sum([a[k] != b[k] for k in range(len(a))])

            # If this new distance is less than the previously observed distance
            # between this amino acid pair, record the new distance
            try:
                if dist < neighbor_dict[(codons[a],codons[b])]:
                    neighbor_dict[(codons[a],codons[b])] = dist
                    neighbor_dict[(codons[b],codons[a])] = dist

            # If we haven't seen pair before, record that distance
            except KeyError:
                neighbor_dict[(codons[a],codons[b])] = dist
                neighbor_dict[(codons[b],codons[a])] = dist

    return neighbor_dict