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
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.
Thanks very much. I see the point and I will post questions more clearly next time.
Join our real-time social learning platform and learn together with your friends!