LOGIC If value matches a value in a dictionary , append associated value


#1

Okay this is late on a Friday and this is something I should probably already know, but I am not sure of the best approach. If I have a dictionary of values like this Zero, A One, B and I have a list, Zero, Zero, One, Zero, One. How could I produce a list that matches using the second values A,A,B,A,B. The solution I am looking for would be variable and have no hardcoded aspects, meaning you could add n amount of different values to the list (Two, Three,ect). I believe there is some recursion and logic, some list.map. Also maybe a list.combine. Trying to do this all OOTB. Jamie


#2

 

 

 

I don’t know if this is the most elegant, but it works!

 

GetFromDictionary.dyn


#3

The Dictionary nodes are not OOTB, they are from Lunchbox. However, the functions appear to work in code blocks too. I do not know if it is because I have downloaded the lunchbox package.


#4

Wait, so that wasn’t terribly robust. If there were a problem, you would get the first value in the dictionary. Here’s a more robust solution, where an incorrect value yields a null value at the end.

GetFromDictionary.dyn


#5

CM - I think this will work trying on a larger example now. Thanks!

 

Tim that dict ds function is interesting, i have to try that out also.


#6

I was able to produce the same results with a slightly different approach. It would be much easier if you could use the NullAllIndecesOf node from the SpringNodes package [image 1], however I replaced this functionality with default nodes to keep everything OOTB [image 2]…

 

 


#7

File: Match.dyn


Pairing Data according to criteria - Dictionary
#8

The “Dictionary.ByKeysValues” node from spring nodes makes an actual dictionary and should perform much faster for large data sets. (because evaluations are not free)


Pairing Data according to criteria - Dictionary
Parameter fron Excel to Revit with vlookup formula
#9


#10