Quantcast

Got Homework?

Connect with other students for help. It's a free community.

  • across
    MIT Grad Student
    Online now
  • laura*
    Helped 1,000 students
    Online now
  • Hero
    College Math Guru
    Online now

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

sakh

Are there any drawback to copying objects like this in Python? a = [1,2] b = list(a)

  • one year ago
  • one year ago

  • This Question is Closed
  1. agdgdgdgwngo
    Best Response
    You've already chosen the best response.
    Medals 2

    Maybe this method of copying lists is the most readable, concise, and quick compared to list comprehensions or for loops with b.append(item), etc. http://henry.precheur.org/python/copy_list The below links also has some notes about the difference between b = list(a), b = a[:], and using some fancy copy module to copy the objects. http://stackoverflow.com/questions/2612802/how-to-clone-a-list-in-python http://stackoverflow.com/questions/184643/what-is-the-best-way-to-copy-a-list-in-python http://stackoverflow.com/questions/184710/what-is-the-difference-between-a-deep-copy-and-a-shallow-copy

    • one year ago
  2. agdgdgdgwngo
    Best Response
    You've already chosen the best response.
    Medals 2

    the first stackoverflow link has a good comparison summary at the end of the first answer where the object in the original list is updated and the copied lists that used methods like a[:] or list(a) share the same updated value of the original object in a, while the deep copied list (which contains entirely new objects instead of references to the same objects pointed to in the original list) still keeps the old value of the object.

    • one year ago
  3. sakh
    Best Response
    You've already chosen the best response.
    Medals 1

    Thanks

    • one year ago
    • Attachments:

See more questions >>>

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.