brain stuck. whats occurring here?
Ben Finney
bignose+hates-spam at benfinney.id.au
Thu Feb 7 23:09:56 EST 2008
"Mark Tolonen" <mark.e.tolonen at mailinator.com> writes:
> <Matthew_WARREN at bnpparibas.com> wrote:
> > I'm after
> > [[[],[],[],[],[]],[[],[],[],[],[]],[[],[],[],[],[]],[[],[],[],[],[]],[[],[],[],[],[]]]
>
> How about:
>
> >>> [[[]]*5]*5
> [[[], [], [], [], []], [[], [], [], [], []], [[], [], [], [], []],
> [[], [], [], [], []], [[], [], [], [], []]]
Not too useful.
>>> foo = [[[]] * 5] * 5
>>> foo
[[[], [], [], [], []], [[], [], [], [], []], [[], [], [], [], []], [[], [], [], [], []], [[], [], [], [], []]]
>>> foo[0][0].append("spam")
>>> foo
[[['spam'], ['spam'], ['spam'], ['spam'], ['spam']], [['spam'], ['spam'], ['spam'], ['spam'], ['spam']], [['spam'], ['spam'], ['spam'], ['spam'], ['spam']], [['spam'], ['spam'], ['spam'], ['spam'], ['spam']], [['spam'], ['spam'], ['spam'], ['spam'], ['spam']]]
As made clear in the rest of the thread, the OP wants every one of
those lists to be different objects.
--
\ "To me, boxing is like a ballet, except there's no music, no |
`\ choreography, and the dancers hit each other." —Jack Handey |
_o__) |
Ben Finney
More information about the Python-list
mailing list