X-Received: by 10.140.161.6 with SMTP id h6mr11319674qhh.1.1449195085230; Thu, 03 Dec 2015 18:11:25 -0800 (PST) X-Received: by 10.50.128.74 with SMTP id nm10mr65684igb.0.1449195085202; Thu, 03 Dec 2015 18:11:25 -0800 (PST) Path: csiph.com!au2pb.net!usenet.blueworldhosting.com!feeder01.blueworldhosting.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!b51no6283249qgf.0!news-out.google.com!l1ni483igd.0!nntp.google.com!mv3no11246547igc.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.python Date: Thu, 3 Dec 2015 18:11:24 -0800 (PST) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=50.100.117.144; posting-account=SZ_svQkAAACWRFG2bDA-zgq8ILyl4-vo NNTP-Posting-Host: 50.100.117.144 References: User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <46a3ad9e-02f9-4bb0-9981-e7dd8fcb8f30@googlegroups.com> Subject: Re: Is there a way to set several list elements a same value with one line code From: Robert Injection-Date: Fri, 04 Dec 2015 02:11:25 +0000 Content-Type: text/plain; charset=ISO-8859-1 Lines: 31 Xref: csiph.com comp.lang.python:99991 On Thursday, December 3, 2015 at 7:59:16 PM UTC-5, MRAB wrote: > On 2015-12-04 00:30, Robert wrote: > > Hi, > > > > I remember that there is a way to set several list elements a same value with > > one line code. Excuse me, I don't remember the accurate syntax on the code > > snippet. But the basic format looks like this. > > > > 1. There is a four-element list, such as: > > bb=[[[]],[[]],[[]],[[]]] > > 2. An assignment line is here: > > bb[0]='a' > > 3. Then, all 4 element of bb is set with the above value. > > bb=[['a'],['a'],['a'],['a']] > > > > The above three line codes are what I guess (I forgot the original tutorial > > now). Do you remember there is such a list application? > > > Do you mean this behaviour: > > >>> bb=[[[]]] * 4 > >>> print(bb) > [[[]], [[]], [[]], [[]]] > >>> bb[0][0]='a' > >>> print(bb) > [['a'], ['a'], ['a'], ['a']] > > ? > > That's because the bb contains 4 references to the same list. Yes! What you post is I want. Thanks.