Giter Club home page Giter Club logo

Comments (2)

dbader avatar dbader commented on June 12, 2024

Thanks for flagging this -- want to send in a pull-request to update that section?

from python-guide.

vbrozik avatar vbrozik commented on June 12, 2024

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:

from python-guide.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.