Dictionary creation

dynamo

#1

Hello Everyone.
I have a basic question.
Please help me with this dictionary.
Why does it come in random combinations? Why a letter “A” doesn’t correspond 101 ???


#2

dont know why but the Lunchbox version of the node gives me this


#3

Dictionaries are unorder collections. There are reasons why the order of items appears seemingly random; there is actually a logical reason why. This video explains how python builds dictionaries and orders key value pairs; I suspect under the hood, Dynamo is doing the same:


#4

But key A does contain 101, just not as the first value of the dictionary :slight_smile:


#5

Dynamo is written in C#. We can take a look what’s under the hood of Dictionary.ByKeysValues node here:

So this node returns ImmutableDictionary object.

From https://docs.microsoft.com/pl-pl/dotnet/api/system.collections.immutable.immutabledictionary-2?view=netcore-2.2 we can learn that ImmutableDictionary is an immutable, unordered collection of keys and values.


#6

I know. I was referring to the mechanics of how dictionaries are allocated memory addresses (hashing) - which that python video explains really well - demonstrating why dictionary key value pairs are seemingly ‘unordered’ and providing an insight and answer the OP if i am not mistaken. All languages which support dictionaries do the same thing, so the specific language in use isn’t important.


#7

I wanted to post a general reply. Still, the node could behave as @m.shcheblykin expected because both C# and IronPython have ordered dictionary classes and they were not used here.


#8

Saves on memory and CPU - order doesn’t matter as values are called for by name.


#9

Yes, my fault. Looks like I didn’t understand the main concept and purpose of these dictionaries


#10

We’re all here to learn :point_right: