List of Dictionaries

Hello,
I do tried but fail to do it by myself.

I have a list of dictionaries.
I need to extract value (value=1) from the dictionary (dictionary=0), which matches the specific value (name=Order in Construction) in the dictionary (dictionary=0).

In other words, I want to get rid of code block (json[0]).
Thank you.

Hello
a solution with a Python Node

listJson = IN[0]

for jsondict in listJson:
	#convert to Python Dictionary
	dictPy = dict(zip(jsondict.Keys, jsondict.Values))
	if dictPy.get("name") == "Order in Construction":	
		OUT = dictPy.get("value")
		break
1 Like

Hello, @c.poupin

Thanks a lot! The code is clear. I need to start learning Python :slightly_smiling_face:

@c.poupin

There is still some error in my case…

You need to make an indent (Tab) on line 6, 7, 8 and 9 like the example from poupin (double indent on 8 and 9)

1 Like

@s.semashka
read this :wink:

1 Like

Thanks @wouter.hilhorst and @c.poupin That’s true… another newbie error.
Any dictionary has “Keys” and “Values” components. What’s now?

And now…

in your first screen can you add the Object.Type node? to get type of dictionary

@c.poupin please find attached below

strange, what your version of Dynamo?

you can try this

listJson = IN[0]

for jsondict in listJson:
	try:
		#convert to Python Dictionary
		dictPy = dict(zip(jsondict.Keys, jsondict.Values))
	except:
		dictPy = jsondict	
	if dictPy.get("name") == "Order in Construction":	
		OUT = dictPy.get("value")
		break

dynamooo

Perfect! That’s work. Thank you!

thank you also, thanks to you I learned that on 2.5 the Dynamo Dictionaries are automatically converted into Python Dictionaries in a Python node as input

2 Likes