I’m trying to compare two dictionaries vie Python script, but the Dynamo return me ‘false’ all the time, why? I’ve tried this algorithm in PyCharm and it is functional but not in Dynamo Python Node, is this a limitation of IronPython? Thank a lost for your thought and ideas.
-lt
you just wanna map two keys and check if the values are the same right?? try the code below
#Preparing input from dynamo to revit
xls_data = {"A":10, "B":40, "C":20}
rvt_data = [{"A":10, "B":40, "C":20}, {"A":20, "B":40, "C":10}, {"A":10, "B":30, "C":30}]
#Do some action in a Transaction
finalchecklist = list()
for dict in rvt_data:
keys = sorted(dict.Keys)
checklist = list()
for key in keys:
if xls_data[key] == dict[key]: checklist.append(True)
else: checklist.append(False)
finalchecklist.append(checklist)
#Final output
OUT = finalchecklist
Perhaps the data types stored within each dictionary is different? One might have strings whereas the other has integers, therefore returning false when comparing 10 to "10".
thanks for your time, unfortunately I didn’t find a way how to return a dictionary. It seems that a solution is to return a list, but that is not what I have wanted. I have checked if both of the inputs have the same data type and they have, so I don’t know where the dog is buried, anyway thanks a lot once again…
I think the two (Dynamo dictionary and python dictionary) are not the same, although you expect them to be interchangeable.
I work around this by returning a list of two lists [keys,values] and then use the node dictionary for keys and values .
Jonathan