In C ++, to access data named 'named' we constantly do:
const unsigned int CHEESE_CAKE = 0;
const unsigned int CHOCOLATE_CAKE = 1;
...
const unsigned int CHERRY_PIE = 1050;
Then, when we want to access a specific resource mapped to a string, we can simply do:
mResource[MyClass::CHEESE_CAKE];
I tried to do this in python in a similar way:
class MyClass:
MY_CLASS_DATA1 = someData(1)
MY_CLASS_DATA2 = someData(1)
But, in my opinion, python member functions are stored in __dict__, which is essentially a hash map displaying O (logn) lookup time.
Is there a way to achieve O (1) performance in python, like in C ++, or is this not possible due to the dynamic nature of python?
source
share