Ouch, that's bizarre. On Fri, Apr 23, 2010 at 12:44 PM, Mark Engelberg < mark.engelb...@alumni.rice.edu> wrote:
> They have every right to be confused. Who would guess that Python > evaluates optional arguments once at compile-time? Heck, I've used > Python for years and I wouldn't have been able to tell you off the top > of my head how Python handles this code. > > That reminds me of a similar gotcha I've unfortunately run into on > more than one occasion. > > # intialize a to be a list of 5 empty lists > a = 5*[[]] > # push a value onto the first list. > a[0].append(1) > > What's a? > > --Mark > > (P.S. Stuff like this drives me nuts, which is why I find myself > gravitating more and more to languages with a richer set of immutable > data structures, e.g., Clojure/Scala/etc., where both of these gotchas > would become a non-issue. I would love to see more immutable > datatypes in Python other than numbers/strings/tuples, although > realistically, I'd say that's unlikely to happen.) > _______________________________________________ > Edu-sig mailing list > Edu-sig@python.org > http://mail.python.org/mailman/listinfo/edu-sig >
_______________________________________________ Edu-sig mailing list Edu-sig@python.org http://mail.python.org/mailman/listinfo/edu-sig