brain stuck. whats occurring here?

Terry Reedy tjreedy at udel.edu
Thu Feb 7 23:34:33 EST 2008


"Mark Tolonen" <mark.e.tolonen at mailinator.com> wrote in message 
news:r4GdnbsfRpVyUTbanZ2dnUVZ_uudnZ2d at comcast.com...
|
| <Matthew_WARREN at bnpparibas.com> wrote in message
| news:mailman.468.1202405913.9267.python-list at python.org...
| > Hallo,
| >
| > I'm after
| >
| > 
[[[],[],[],[],[]],[[],[],[],[],[]],[[],[],[],[],[]],[[],[],[],[],[]],[[],[],[],[],[]]]
| >
|
| How about:
|
| >>> [[[]]*5]*5
| [[[], [], [], [], []], [[], [], [], [], []], [[], [], [], [], []], [[], 
[],
| [], [], []], [[], [], [], [], []]]

Because that is actually only 1, not 25, empty lists
>>> a=[[[]]*5]*5
>>> a[0][0].append('ha')
>>> a
[[['ha'], ['ha'], ['ha'], ['ha'], ['ha']], [['ha'], ['ha'], ['ha'], ['ha'], 
['ha']], [['ha'], ['ha'], ['ha'], ['ha'], ['ha']], [['ha'], ['ha'], ['ha'], 
['ha'], ['ha']], [['ha'], ['ha'], ['ha'], ['ha'], ['ha']]]

tjr






More information about the Python-list mailing list