How to return a Dictionary out of Python node?

Hello everybody,
I have been far for sometimes, Dynamo has improved so far that I feel a newbie again.
I am trying to create a Dictionary from a couple of list, putting the level as a key and the object list as a value
but I do not know how can I output the Dictionary from the Python node.
Maybe is silly but I Have not found the right sintax yet.
I will reuse the same method to another list than I can compare both dictionary with keys.

Could it be that you left “IN” off your TUP input?

1 Like

Dynamo doesn’t currently support printing or outputting Dictionaries from Python nodes. You can use them in code just can’t preview them in watch nodes. If you wrap that dictionary into some other class then it will work just fine.

It was brought up here already: https://github.com/DynamoDS/Dynamo/issues/3378

As an alternative, you could also return the key/value pairs of the dictionary and reuse them at a later time:

a, b = range(5), range(4, -1, -1)
OUT = dict(zip(a, b) ).items()
3 Likes

Thank you very much for all the prompt answers.

@Dimitar_Venkov
i don’t really understand how to wrap a complex dict.
i am able to extract only the first (root) key but no further (existing) keys!
values() are not accessible within python too?
->dictionary.items()
produces just above error message
do you have any suggestion?
tx peter

Hi Peter,

It sounds like you have nested dictionaries. If that’s the case, you’ll need to call .items() recursively on each nested dictionary.

Alternatively, if you just want to pass the dictionary down the graph to another python node, you could wrap it into a dummy python object and then unwrap it in the next python node.

class dummy(object):
	def ToString(self):
		return 'container'

container = dummy()
data = {'first':{1:"a", 2:"b", 3:"c"}, 'second':{1:"a", 2:"b", 3:"c"} }
container.data = data

OUT = container

image

4 Likes

dimitar, thank you!

again helping me out of deep s…

best peter