- Notifications
You must be signed in to change notification settings - Fork5.9k
Open
Description
In the Code Style chapter examples -Short Ways to Manipulate Lists there is an example "Add three to all list members."
"bad"
foriinrange(len(a)):a[i]+=3
"good"
a= [i+3foriina]
Unfortunately the "bad" and "good" examples do a different things:
- "bad" modifies the original list in place
- "good" creates a new modified list and does not change the original object - not exactly "Add three to all list members."
Although the "good" code looks cleaner the result could be unwanted for example in case of huge lists or required side-effect of modifying the original list. The code at least needs an explanation.
Metadata
Metadata
Assignees
Labels
No labels