[Edu-sig] teaching Python

Mark Engelberg mark.engelberg at alumni.rice.edu
Sat Apr 24 02:49:25 CEST 2010


On Fri, Apr 23, 2010 at 2:41 PM, David MacQuigg
<macquigg at ece.arizona.edu> wrote:
> Would you rather have Python do something different?

My own preference is that I would like 5*[[]] to be syntactic sugar for:
[ [ ] for i in range(5)]

I find this to be more intuitive, and I believe this is what most
people incorrectly assume the syntax expands to.

If that's the way it worked, literals would always create fresh copies
each time through the loop, but if you still want shared behavior, you
could do it explicitly with something like:
x = []
a = 5*x

Anyway, every language has its shares of gotchas.  It's just this is
one I've gotten burned by more than once.


More information about the Edu-sig mailing list