I have a question about the way List and Dict are called in Python.
Personally, I thought that dict and list object calling method were the same, but the result was completely different from what I expected.
I thought both List and Dick would return the result if they found a matching value through repetition, but I checked that Dick calls are faster than List calls (?), and I wonder how this difference can occur.
Isn't it going through the same process in that it finds a matching value?python list dictionary
Let me compare the list with the three.
You make a list and three of the same size, and you determine which values are in the list/set. To check the time difference, I timed it repeatedly.
The membership check on the list takes much longer. We're going to take each element out of the list and compare it. So, it will take time in proportion to the size of the list. However, the three are implemented as hash tables, so they search more efficiently. You can study if you need a specific implementation. I had a roughly sorted index, and I thought I'd do a binary research on it, so I moved on.
In dictionaries, whether or not keys exist is repeatedly used very importantly, so dictionary keys will be made of three, not a list. So it's different.
The list and three search times are almost the same as those in the table indexed in the database and those in the table not indexed. If you search without indexing, the application gets really slow. That's right.
© 2022 pinfo. All rights reserved.