News for hackers. Stuff that matters.
Re:Code Like a Pythonista: Idiomatic Python by daeken on Saturday October 22, 2011 @09:36PM (#3144859)
Just make sure that when you do this, you're not initializing it with mutable objects, e.g. lists.

    x = [[0]] * 2
    print x[0], x[1] # prints [0] [0]
    x[0].append(1)
    print x[0], x[1] # prints [0, 1] [0, 1]
That's because the objects inside the repeated list are simply references to the same object internally.

There are no comments on this comment yet.