Warning: IronPythonEvaluator.EvaluateIronPythonScript operation failed. 'string' does not contain a definition for 'Key'

Anybody know a workaround for this bug when creating a dictionary from two lists?

Warning: IronPythonEvaluator.EvaluateIronPythonScript operation failed.
‘string’ does not contain a definition for ‘Key’

in IronPython console a test is working fine:

keys = [“name”, “age”, “food”]
values = [“Monty”, “42”, “spam”]
test_dict = {k : v for k, v in zip(keys, values)}
test_dict
{‘age’: ‘42’, ‘name’: ‘Monty’, ‘food’: ‘spam’}

Help greatly appreciated. Thanks!

Well actually “test_dict{‘age’: ‘42’, ‘name’: ‘Monty’, ‘food’: ‘spam’}” just redifines the dictionary. It does exactly the same as the previous lines.
Otherwise it seems correct to me.

keys = ["name", "age", "food"]
values = ["Monty", "42", "spam"]
dict = {k : v for k, v in zip(keys, values)}
#Assign your output to the OUT variable.
OUT = dict[IN[0]]
1 Like

@ victor_kuzev - thanks I’m trying to pull out a dictionary from two lists, as in regular python (or ironpython). like in the screen capture. thanks for your help.

Hi!
You set dataEnteringNode = IN[0] then = IN[1] you should delete those lines. Also, you don’t need to declare the dictionary first - the sixth line is not necessary.

Also you can use Dictionary.ByKeyValues from Springs package or just a code block:

dataEnteringNode = IN
keys = IN[0]
values = IN[1]
dict = {k : v for k, v in zip(keys, values)}
#Assign your output to the OUT variable.
OUT = dict[IN[2]]

@ viktor_kuzev - thanks for reply.

  1. I instantiate the dictionary from a diff. code line - I just did not delete that line - that is not an issue.

  2. the IN[0] and IN[1] will pull in the real lists, I cannot delete them - this example of the code was with dummy lines.

  3. I’m not looking to pull the values based on keys, I’m simply trying to create a dictionary based on two lists that I input in pycode (IN[0] will be the keys and IN[1] will be the values). So I have a list IN[0] and a list IN[1], from these two I need to pull out a dictionary via py node as I simply do it in python(iron). Thanks.

How would you expect to use the python dictionary in the Dynamo enviroment?

You can use design script to achieve the same:

“How would you expect to use the python dictionary in the Dynamo environment?”

The lists that create these dictionaries, are part of large datasets that are processed outside dynamo/revit via Spyder (NumPy+Pandas), then the new values are overwritten on top of old ones.
At the end is about overwrite the values in the dictionary, based on new values from the outside dictionary.
The struggle is with IronPython inside of Dynamo. Outside, things are working fine. Probably I’ll go that route and avoid Dynamo for that part.
Thanks.

It turns out that there is a known issue reported on github about the error you get:

I had read that before posting, that is why I asked about a workaround. Thanks.