On Fri, Apr 23, 2010 at 2:41 PM, David MacQuigg
<macqu...@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.
_______________________________________________
Edu-sig mailing list
Edu-sig@python.org
http://mail.python.org/mailman/listinfo/edu-sig

Reply via email to