New submission from Michael Williamson:
The Python docs for the operator module include an example using map and
setitem to "Build a dictionary that maps the ordinals from 0 to 255 to their
character equivalents.":
d = {}
keys = range(256)
vals = map(chr, keys)
map(operator.setitem, [d]*len(keys), keys, vals)
Since map is lazy since Python 3, the dictionary d is never actually changed in
this example. I'm not entirely sure what the idiomatic way to fix the example
is since it strikes me as being fairly unidiomatic to begin with, but the
simplest would be to call list on the result of map to force evaluation (patch
attached).
----------
assignee: docs@python
components: Documentation
files: doc-operator-example.patch
keywords: patch
messages: 225141
nosy: docs@python, mwilliamson
priority: normal
severity: normal
status: open
title: operator.setitem example no longer works in Python 3 due to lazy map
versions: Python 3.1, Python 3.2, Python 3.3, Python 3.4, Python 3.5
Added file: http://bugs.python.org/file36333/doc-operator-example.patch
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue22180>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com