Skip to content
Advertisement

How to compare a list of routes with a dictionary of costs between arcs?

Hello to the whole community,

I have a question about creating an automatic method (function or loop+) to declare a route cost variable, which involves the sum of each of the c_i,j arcs.

Example:

JavaScript

I would like to get help to reach a RouteCost variable that compares the list with the dictionary and will add each of the arcs it finds per route. For example, there would be a list of costs for the 3 routes:

JavaScript

Thank you for your help and keep up the good work to all.

Advertisement

Answer

This can be performed using a nested list comprehension:

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement