Lookup Value equivalent in Dynamo?

I’m sure this is a simple one, but I’m not having luck finding the right wording.

I’m looking to return a string depending on the value from a list.
I want to look at List 1, compare it to List 2, and report the corresponding value from List 3 into a new list. This is just an incomplete example.

Hopefully I’ve explained it well enough, basically the same as the vlookup function in excel.

The intention is that in this example, List 4 should read:
[Yellow, Blue, Red, Red, Red, Green, etc]

The best way to do this is with a dictionary.

The alternative would be to get the index of the item in List 2 and use that to return the item at the same index of List 3.

4 Likes

Right, I think my approach should revolve around a dictionary?
Am I on the right track?
How do I then apply the dictionary to my list?

Thanks Nick, I think I stumbled upon this as you were typing!
Now I have my dictionary, how do I go about using it?

Hello, Solution with dictionary (note the keys are necessarily strings, and your dictionary will not be stored)

cordially
christian.stan

1 Like

Here is a relay (transmitted by M.Jacob), it is more complete

cordially
christian.stan

I’m not sure how programatically inefficient it is, but generally if it’s a simple 2 list exercise I prefer to use indexing to get the corresponding values instead. You can use IndexOf and GetItemAtIndex but this is an example made in Python (my Revit is in a big print currently):

things1 = ["a","b","c"]
things2 = ["d","e","f"]

convert = ["a","b","c","a","b","c"]

results = []

for c in convert:
    ind = things1.index(c)
    get = things2[ind]
    results.append(get)

print(results)

I find it much more legible versus the dictionary approach. In principle you are asking, in things1 where do you occur, then getting that position from things2. One benefit is if you use Python you can also use try/except to catch when that object doesn’t occur in the first list and build in an exception (e.g. maybe you call on an empty string versus triggering an error/null).

If you want to carry multiple properties in parallel, then a dictionary is a good approach. Alternatively if in an environment like Python a more common approach is to create a custom class which you can store and define properties for.

3 Likes