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]
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.