<[EMAIL PROTECTED]> schrieb im Newsbeitrag news:[EMAIL PROTECTED] | I'm new to python. I tried doing this | | >>> x = [[]] * 3 | >>> print x | [ [] [] [] ] | >>> x[0].append( 2 ) | [ [2] [2] [2] ] | | I confused with the last line output. I actually expected something | like | | [ [2] [] [] ] | | Can anyone give me an explanation. help!!
The library reference can! See http://docs.python.org/lib/typesseq.html Look at the section "notes (2)": """Values of n less than 0 are treated as 0 (which yields an empty sequence of the same type as s). Note also that the copies are shallow; nested structures are not copied. This often haunts new Python programmers; consider: >>> lists = [[]] * 3 >>> lists [[], [], []] >>> lists[0].append(3) >>> lists [[3], [3], [3]]"""etc. -- Vincent Wehren -- http://mail.python.org/mailman/listinfo/python-list