Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

gene3141

  • 2 years ago

Hi, I have a query about problem 5 on Quiz 1. The solution says: v1 = v1[:] v2 = v2[:] at the beginning. Can anyone explain to me why we need to do this? Thanks

  • This Question is Open
  1. bwCA
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 1

    post the complete problem/solution that would prevent the original list object from being mutated. are v1 and v2 function arguments? copy = original[:] is a way to copy a list, it creates a completely new list object and assigns it to the variable on the left side of the equal sign http://henry.precheur.org/python/copy_list http://python.net/~goodger/projects/pycon/2007/idiomatic/handout.html#other-languages-have-variables http://effbot.org/pyfaq/how-do-i-copy-an-object-in-python.htm it helps to reference the course you are taking - ppl taking OCW 6.00 (2008) and OCW 6.00c (2011) and sometimes the edX 6.00 post here - same basic course with similar problems and different pset numbers. please use a code pasting site to post code: - http://dpaste.com - http://pastebin.com - https://gist.github.com/ - http://pastie.org - http://codepad.org - http://ideone.com - http://www.repl.it/ paste your code there and post the link here. select Python syntax highlighting when u paste.

  2. gene3141
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Thanks very much. I see the point and I will post questions more clearly next time.

  3. Not the answer you are looking for?
    Search for more explanations.

    • Attachments:

Ask your own question

Sign Up
Find more explanations on OpenStudy
Privacy Policy