weirdness with list()

Cameron Simpson cs at cskk.id.au
Mon Mar 1 06:29:34 EST 2021


On 01Mar2021 00:06, MRAB <python at mrabarnett.plus.com> wrote:
>I'm not seeing a huge problem here:
>
>Python 3.9.2 (tags/v3.9.2:1a79785, Feb 19 2021, 13:44:55) [MSC v.1928 
>64 bit (AMD64)] on win32
>Type "help", "copyright", "credits" or "license" for more information.
>>>> import time
>>>> class A:
>...     def __len__(self):
>...         return 1024**3
>...     def __iter__(self):
>...         yield from ()
>...
>>>> a = A()
>>>> len(a)
>1073741824
>>>> s = time.time()
>>>> list(a)
>[]
>>>> print(time.time() - s)
>0.16294455528259277

3.9.1 on MacOS: 14.529589891433716
3.9.2 on MacOS: instant again

Interesting. - Cameron Simpson <cs at cskk.id.au>


More information about the Python-list mailing list