Re: Lazy lists for use with large dictionaries

Anton Hartl (hartl@Informatik.TU-Muenchen.DE)
29 Sep 1994 15:26:29 GMT

Guido.van.Rossum@cwi.nl writes:
>Have you tried? dict.keys() makes one fast scan over the dictionary
>(internally, the iteration you want *does* exist) copying the pointers
>to the key objects into a pre-allocated list object of the right size.
>The iteration time isn't lost (since you'll have to iterate anyway --
>unless in the majority of cases your loop terminates very prematurely
>(which I doubt since you're getting the keys in random order). Since
>the keys aren't copied (only the pointers are) the only cost is 4000
>to 40,000 bytes.

>Does this make sense?
Yes, it does. Specifically as you obviously have implemented the keys()
methods in an efficient way. That was the information I was looking for.

Furthermore adding something like lazy lists would likely result in
increased implementation complexity and it is questionable wether
it is worth the effort.

>(This is actually the second time someone asks this -- maybe I should
>add it to the FAQ.)
I guess that is a good idea.

-Toni