New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
operator.setitem example no longer works in Python 3 due to lazy map #66376
Comments
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). |
Heh. There was a discussion in bpo-22106 about valid examples for using 'pass'. This case is analogous to the one I came up with. for x in map(...):
pass that avoids building a list. Not that any of it is idiomatic, as you say. |
The whole example is bad and should be removed or replace with something else:
|
I'm not sure there are ANY examples of operator.setitem that couldn't be done a better way without it. How about we remove it and leave the examples for things that people ought to be doing. |
Le 10/08/2014 13:20, Raymond Hettinger a écrit :
Agreed. operator.setitem() isn't really ever used in my experience. |
New changeset 9c250f34bfa3 by Raymond Hettinger in branch '3.4': |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: