It really depends on the case. But a good GHPython rule of thumb is to treat lists as lists and trees as trees explicitly (i.e. don’t use implicit cycles outside simple cases, there are more good reasons such as performance). For instance, in your case the keys could be a flat list and the code could be reduced to this:
230121_ToGHPythonDict_01.gh (13.3 KB)
Yes that was it. I should have been more precise, my bad.
It’s a long story, see for instance this topic: