Skip to content

Instantly share code, notes, and snippets.

@Shadid12
Created March 19, 2018 23:27
Show Gist options
  • Save Shadid12/6e6711f41bb87155ae6a8be489afd328 to your computer and use it in GitHub Desktop.
Save Shadid12/6e6711f41bb87155ae6a8be489afd328 to your computer and use it in GitHub Desktop.
def distanceBetween(self, cities=[]):
"""
Calculates distance of the route
Args:
cities (str[]): The array of cities
Returns:
int: calclated distance
"""
distance = 0
'''
for every cities we will be looking at the adjacent route and
adding the weight of route to total distance
'''
for i in range(len(cities)):
root_node = cities[i]
if i + 1 < len(cities):
next_node = cities[i+1]
if next_node in self.routesTable[root_node]:
distance = distance + self.routesTable[root_node][next_node]
else:
return "There is no route"
return distance
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment