[New-bugs-announce] [issue47028] Incorrect behaviour when zipping a bunch of maps
John K.
report at bugs.python.org
Tue Mar 15 11:38:25 EDT 2022
New submission from John K. <khoodolphin at gmail.com>:
map(f, itr) is supposed to be the lazy way to do [f(val) for val in itr]. However, when unpacking and zipping a list of maps, I get a different result from when evaluating eagerly. More precisely:
Python 3.10.2 | packaged by conda-forge | (main, Mar 8 2022, 15:53:57) [GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> maps = [map(lambda x: x**i, range(7)) for i in range(5)]
>>> for z in zip(*maps):
... print(z)
...
(0, 0, 0, 0, 0)
(1, 1, 1, 1, 1)
(16, 16, 16, 16, 16)
(81, 81, 81, 81, 81)
(256, 256, 256, 256, 256)
(625, 625, 625, 625, 625)
(1296, 1296, 1296, 1296, 1296)
>>> lists = [[x**i for x in range(7)] for i in range(5)]
>>> for z in zip(*lists):
... print(z)
...
(1, 0, 0, 0, 0)
(1, 1, 1, 1, 1)
(1, 2, 4, 8, 16)
(1, 3, 9, 27, 81)
(1, 4, 16, 64, 256)
(1, 5, 25, 125, 625)
(1, 6, 36, 216, 1296)
----------
components: Interpreter Core
messages: 415256
nosy: khoodolphin
priority: normal
severity: normal
status: open
title: Incorrect behaviour when zipping a bunch of maps
type: behavior
versions: Python 3.10
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue47028>
_______________________________________
More information about the New-bugs-announce
mailing list