Created
March 19, 2018 23:27
-
-
Save Shadid12/6e6711f41bb87155ae6a8be489afd328 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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