Comments (2)
Thanks for flagging this -- want to send in a pull-request to update that section?
from python-guide.
Excuse my delayed reply. I am still learning Python a lot and in many cases I do not know what is the best way to perform certain task in the language. Also I am not sure if I know English good enough to contribute to an English book. So certainly I need a discussion first :)
Regarding the example above I would explain:
For large lists it could be inappropriate to create a new list to replace the old one because of memory requirements. In such cases the good solution is to modify the list in-place:
for i, _ in enumerate(a): a[i] += 3
PS: Originally I thought that the code below would be the right solution but as the original "good" solution it also creates a new list and only then it assigns its elements to the original list.
a[:] = (i + 3 for i in a)
See:
- https://stackoverflow.com/questions/53286531/assign-iterators-to-a-python-slice
- https://stackoverflow.com/questions/11877212/python-slice-assignment-of-generator-to-list
from python-guide.
Related Issues (20)
- ?
- How can i display image from mysql to python gui ? HOT 2
- Python 2 syntax in examples, why? HOT 5
- Python guide
- Python
- Suggested function for installing packages globally does not work as intended
- Addition of Poetry to "Using virtualenvs..." section HOT 2
- Page 404 error HOT 1
- Would a section on performance be of interest?
- (please help) having problem in my code
- Salut
- Python
- Manual de python HOT 1
- Is this still the best practices of python3? HOT 1
- I want to learn python HOT 1
- Hello HOT 1
- Blockchain development starter
- Python
- Test
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from python-guide.