This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: list() destroys map object data
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.5
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: Steven Reed, ned.deily
Priority: normal Keywords:

Created on 2016-04-09 20:22 by Steven Reed, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (2)
msg263111 - (view) Author: Steven Reed (Steven Reed) Date: 2016-04-09 20:22
Example repro:

Python 3.5.1 (v3.5.1:37a07cee5969, Dec  6 2015, 01:54:25) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> x=map(bool,[1,0,0,1,1,0])
>>> x
<map object at 0x0000000000AC51D0>
>>> list(x)
[True, False, False, True, True, False]
>>> list(x)
[]
>>> x
<map object at 0x0000000000AC51D0>
msg263112 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2016-04-09 20:28
This is behaving as expected.  In Python 3, map() returns an iterator, so the first list(x) exhausts that iterator so that the second list(x) returns an empty list.  This is a difference from Python 2 where map() returns a list.  See:

https://docs.python.org/3.5/whatsnew/3.0.html#views-and-iterators-instead-of-lists
https://docs.python.org/3/library/functions.html#map
History
Date User Action Args
2022-04-11 14:58:29adminsetgithub: 70912
2016-04-09 20:28:54ned.deilysetstatus: open -> closed

nosy: + ned.deily
messages: + msg263112

resolution: not a bug
stage: resolved
2016-04-09 20:22:26Steven Reedcreate