First Item of a List - Basic Python?

Hi,

I am used to Python scripting in Rhino and Grasshopper through Rhinoscript Syntax.
I am getting into Python in Dynamo and seem to be running into issues with basic Python syntax.

Essentially, I have a list of FamilyInstances from a Panelized DividedSurface as an input.
Using a list of each panel’s Z coordinate as a Key, I sorted the list of Panels in ascending order.

The SortByKey in Dynamo returns both the sorted Key List and the sorted Data List as lists within themselves, thus the output of the node is a list of 2 lists.

In the below image, the Watch node displays the 2 lists after sorting.

I would like to output just the sorted family instances, so I thought square brackets would do the trick:
OUT=newPanels[0]
but it doesnt and I don’t know why.
Any ideas?

I get the error message:
Warning: IronPythonEvaluator.EvaluateIronPythonScript operation failed.
Traceback (most recent call last):
File “”, line 43, in
KeyError: The given key was not present in the dictionary.

Here is my Python Node. The lines in question are at the bottom.

The output of that node is a Dictionary, not a list so you can’t use the normal way to index it (using [0] or [1]). Instead, you have to call it by its dictionary key, which for this node is “sorted list”. Try using newPanels["sorted list"] instead.

Cheers, works now.
But i was wondering why the Watch node displays the data as a List intead of a Dictionary?
8222019-3

What version of Dynamo are you using? In 2.0+ it shows as a dictionary but that is because Dynamo added a better dictionary system in those versions.

dictionaryoutput

1 Like

Gotcha!

Thanks!