Match List, Return Corresponding Value

Hi everyone,
I feel the answer to this is almost within my reach but I can’t get to it.
I have a list A: 11-London, 12-Riyadh, 13-Denver, 14-Gondor
I have list B: London, London, Denver, Gondor, London, Riyadh, Gondor
I want to compare list B with list A and create a list C with corresponding number values: 11,11,13,14,11,12,14

I was able to achieve values as 0 to 3 using List.IndexOf. But I would really like to be able to match them to 11-14.

Have you used Dictionaries before?
I would create a dictionary of {city: number} pairs, i.e. cities are keys and numbers are values.
use the Dictionary.ByKeyValues node to create the dictionary.

After creating this dictionary you can retrieve numeric values based on the keys given in list B.
use Dictionary.ValueAtKey node to retrieve values.

1 Like

You were almost there, just needed that last step.
The dictionary suggestion is a very good one, particularly if you need to pull a lot more data.

Just tried out dictionaries, and they’re pretty neat!
Guess I just added a dictionary to my vocabulary!