Access Is it possible to access Python O (1) data?

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]; // constant time O(1) access

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?

+3
source share
4 answers

- O (1). , O (log n). Python - O (1).

+4

, : python O (1) (. TimeComplexity python). , .

python ++ - .
, , __slots__ ; , , , , - .

+3

, . O (1) .

, , -, , .

: , , Python ++ ? , ! !

0

, n log n? dict , , , O (1)

0
source

All Articles