Helper method for clustering that takes a list of all of the things being
    clustered (which are assumed to be binary numbers represented as strings),
    and an int representing the maximum number of clusters that are allowed.

    Returns: A dictionary mapping cluster ids to lists of numbers that are part
    of that cluster.

def do_clustering(types, max_clust):
    """
    Helper method for clustering that takes a list of all of the things being
    clustered (which are assumed to be binary numbers represented as strings),
    and an int representing the maximum number of clusters that are allowed.

    Returns: A dictionary mapping cluster ids to lists of numbers that are part
    of that cluster.
    """
    # Fill in leading zeros to make all numbers same length.
    ls = [list(t[t.find("b")+1:]) for t in types]
    prepend_zeros_to_lists(ls)

    dist_matrix = pdist(ls, weighted_hamming)
    clusters = hierarchicalcluster.complete(dist_matrix)
    clusters = hierarchicalcluster.fcluster(clusters, max_clust,
                                            criterion="maxclust")

    # Group members of each cluster together
    cluster_dict = dict((c, []) for c in set(clusters))
    for i in range(len(types)):
        cluster_dict[clusters[i]].append(types[i])

    return cluster_dict