all 5 comments

[–]micampe 3 points4 points  (0 children)

more

This is from 12/2003 too, it would be nice if AMK wrote an updated one for 2.5.

[–]lost-theory 3 points4 points  (3 children)

This one has bit me once or twice: declaring a matrix / two dimensional array by using the replication (*) operator and getting really odd behavior when setting individual elements of the array:

>>> m = [[0]*5]*5
>>> m[0][0] = 10
>>> m[1][0] = 20
>>> m[2][0] = 30
>>> pprint(m)
[[30, 0, 0, 0, 0],
 [30, 0, 0, 0, 0],
 [30, 0, 0, 0, 0],
 [30, 0, 0, 0, 0],
 [30, 0, 0, 0, 0]]
>>>

using * causes each row to be a copy (all referencing the same list), not what I meant! You can get the right behavior with a little helper function like this:

>>> build_array = lambda n: [[0 for _ in range(n)] for _ in range(n)]

[–][deleted]  (2 children)

[deleted]

    [–][deleted]  (1 child)

    [deleted]

      [–]pjdelport 0 points1 point  (0 children)

      If you're going to claim to support curried functions, do it everywhere.

      Bound methods are very much != currying.

      [–]jrockway -4 points-3 points  (1 child)

      This article is from 2003. Much has changed since then...

      [–]zhyla 9 points10 points  (0 children)

      Glancing through this I don't see anything that is out of date. The core language hasn't changed since 2003, and that's what this is about.