def cost_tour(graph, tour):
 steps = zip(tour[0:(-1)], tour[1:])
 cost = sum([graph[(step_from, step_to)] for (step_from, step_to) in steps])
 return cost

def cost_tour ( graph , tour ) : steps = zip ( tour [ 0 : ( - 1 ) ] , tour [ 1 : ] ) cost = sum ( [ graph [ ( step_from , step_to ) ] for ( step_from , step_to ) in steps ] ) return cost
calculates the travel cost of given tour through a given graph .