Kent Johnson wrote:
jrlen balane wrote:
basically, i'm going to create a list with 96 members but with only one value:
is there a shorter way to write this one???
[1] * 96

Just a note on this ---

This will work fine for immutable types (such as integers or strings). But you can get into trouble if you do this with mutable types.

eg:

>>> l = [[]] * 10  # A list of ten empty lists
>>> l
[[], [], [], [], [], [], [], [], [], []]
>>> l[3].append(2)
>>> l
[[2], [2], [2], [2], [2], [2], [2], [2], [2], [2]]

--
John.
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to