def count_hops(data, definition, def_args, year, A, B): scipy_matrix = scipy.asmatrix(scipy.array(unsigned_adjacency_matrix(data, definition, def_args, year))) multiplied_matrix = scipy.asmatrix(scipy.array(unsigned_adjacency_matrix(data, definition, def_args, year))) hop_count = 1 while hop_count < len(data.countries()): if multiplied_matrix.tolist()[index_of_country(A)][index_of_country(B)] != 0: return hop_count multiplied_matrix = memoize_matrix_mult(multiplied_matrix, scipy_matrix) hop_count += 1 return INFINITE_HOPS
from project.countries import index_of_country, falklands_war_countries print index_of_country("USA") print "\n".join(["%s,%d" % (C, index_of_country(C)) for C in falklands_war_countries])