Commit 25eb54ae authored by Roberts Ivanovs's avatar Roberts Ivanovs
Browse files

Function for interpreting the 'distances.txt' file

parent 567ea071
import csv
def generate_matrix(default=None):
with open('distances.txt', 'r', encoding="IBM775") as old_dist:
reader = csv.reader(old_dist, delimiter='\n')
cities = []
matrix = []
for ind, val in enumerate(reader):
if ind == 0:
cities = [i for i in val[0].split("\t")]
path_len = [i for i in val[0].split("\t")]
matrix.append([int(i) for i in path_len[1:]])
return {"matrix": matrix, "cities": cities}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment