[New-bugs-announce] [issue4337] Iteration over a map object with list()

Jean-Michel Fauth report at bugs.python.org
Mon Nov 17 16:54:36 CET 2008


New submission from Jean-Michel Fauth <wxjmfauth at gmail.com>:

win XP sp2, Py3.0c2

I had to face an annoying problem when iterating over a map object.

With a range class, this works

>>> r = range(5)
>>> list(r)
[0, 1, 2, 3, 4]

With dict_keys/values/items objects, the following works

>>> d = {1: 'a', 2:'b', 3:'c'}
>>> list(d.keys())
[1, 2, 3]
>>> list(d.values())
['a', 'b', 'c']
>>> list(d.items())
[(1, 'a'), (2, 'b'), (3, 'c')]

But with a map object...

>>> def plus(i):
        return i + 1

>>> a = list(range(3))
>>> a
[0, 1, 2]
>>> r = map(plus, a)
>>> r
<map object at 0x01371570>
>>> for e in r: print(e)

1
2
3
>>> list(r)
[]
>>> #empty list!

Bug or feature?

----------
components: None
messages: 75965
nosy: jmfauth
severity: normal
status: open
title: Iteration over a map object with list()
versions: Python 3.0

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue4337>
_______________________________________


More information about the New-bugs-announce mailing list