Skip to content
Advertisement

Fill in empty value in dictionary based on matching value in separate dictionary (Python)

I am trying to output a dictionary that fills in values already defined by another dictionary. The values that have not been defined return false. However my output is not the order it should be in.

Code:

JavaScript

Output:

JavaScript

The Output I am looking for (in the ‘Direction’ key):

JavaScript

Advertisement

Answer

Since you enumerate through longRoute first, the order of subRoute['Direction'] will depend on the order of longRoute['StepName'] instead of subRoute['StepName'].

Just loop through subRoute first to preserve the order, then compare against longRoute.

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