DEV Community

Discussion on: SpeedUp Python List and Dictionary

Collapse
 
dwd profile image
Dave Cridland

Both are actually the same effect. When you call data.get(...), you're calling the method, of course, but also looking up the method in the data object's internal dictionary, called __dict__. What the above article is showing is that there's some savings to be made if you cache the lookup.

He's not optimizing a list at all, but he is optimizing a dict - in both cases.

Because data[num] = ... is actually data.set(num, ...), there's another candidate for optimization there, as well - but by now you can probably guess what it is.