Hi! There's a line (or two identical ones) that i don't understand in the sample solution to Pset8. here's my solution: http://dpaste.com/782865/ and the sample one: http://dpaste.com/782866/ 1: why have they commented out and replaced line 11? 2: what's with lines 7 and 16? avoiding some type of problem? Thanks!
what data type does virus.reproduce() return? line 11 looks like it should work. I wonder if it is a quirk in the interpreter and lines 12 and 13 force execution order. lines 7 and 16 are using list comprehensions (which are very cool) ... what datatype is newViruses?? they might be doing that to make a completely separate/new copy of newViruses. - there are other ways to accomplish that.
Hey! reproduce() returns an instance of the ResistantVirus class, and newViruses is just a list of such viruses after some method, like doesClear() is used on them. the sample solution switches between viruses and newViruses twice and i don't really understand why. Yeah list comprehensions seem cool, but what's the use here? isn't it equivalent to viruses = newViruses? oh, and does it matter in which side of the "=" smthg is? ie is (viruses = newViruses) = (newViruses = viruses)?
as a matter of fact, it's a bit too cool..: how should i interpret [[row[i] for row in matrix] for i in range(4)] [[1, 5, 9], [2, 6, 10], [3, 7, 11], [4, 8, 12]] that transposes a 3x4 matrix?
using a list comprehension gives you a completely separate object than the original list. sometimes this matters. http://dpaste.com/783441/ http://henry.precheur.org/python/copy_list http://effbot.org/zone/python-list.htm http://python.net/~goodger/projects/pycon/2007/idiomatic/handout.html#other-languages-have-variables not sure what you are asking but that list comprehension will transpose a 4x3 to a 3x4. (or whatever) http://dpaste.com/783444/
Join our real-time social learning platform and learn together with your friends!