Message75965
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? |
|
Date |
User |
Action |
Args |
2008-11-17 15:54:37 | jmfauth | set | recipients:
+ jmfauth |
2008-11-17 15:54:36 | jmfauth | set | messageid: <1226937276.11.0.323552231555.issue4337@psf.upfronthosting.co.za> |
2008-11-17 15:54:35 | jmfauth | link | issue4337 messages |
2008-11-17 15:54:34 | jmfauth | create | |
|