I novice, in the Leetcode brush problem in the process of many problems, so this summary, not regularly updated.
1, in the creation of a two-dimensional list, I will use a = [[0] * 5] * 5, but this output will often be the same as expected, I always thought it was my program has a problem, Baidu for a long time also do not know where the error, and then see others the solution, You changed a code to create and initialize the list, and the result is run, and the error is:[[]] is a list containing an empty list element, so [[]]*3 represents 3 references to this empty list element, and modifying any one element changes the entire list . So the way I used to do this now is to use a list-generating formula:a = [[0] * 5 for _ in Xrange (5)] Link: http://www.cnblogs.com/btchenguang/archive/2012/01/30/23324 79.html
2, in fact, and 1, the B list is known, when I want to perform replication list B and modify the copied list A when (a = b) , if I change a after the value of B will also change, because they are now pointing to the same list, if you want to copy can be executed a = b[:], with a shard operation.
My error summary when I use Python to brush a question