Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python.': 0.02; 'python,': 0.02; 'emulate': 0.07; '[0,': 0.09; 'array.': 0.09; 'subject:using': 0.09; 'to:addr:comp.lang.python': 0.09; 'cc:addr :python-list': 0.10; 'def': 0.10; '"*"': 0.16; '-tkc': 0.16; '0],': 0.16; ':-p': 0.16; 'charge,': 0.16; 'offsets': 0.16; 'wrote:': 0.17; 'tim': 0.18; '>>>': 0.18; 'platforms': 0.18; 'subject:) ': 0.20; 'written': 0.20; 'gcc': 0.22; 'programming': 0.23; 'sets': 0.23; 'cc:no real name:2**0': 0.24; 'cc:2**1': 0.24; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'header :User-Agent:1': 0.26; 'skip:[ 10': 0.26; 'subject:list': 0.28; '>>>>': 0.29; 'style.': 0.29; 'array': 0.29; 'anybody': 0.32; 'instruction': 0.32; 'subject:lists': 0.32; 'could': 0.32; 'received:google.com': 0.34; 'list': 0.35; 'from:addr:googlemail.com': 0.35; 'received:209.85.220': 0.35; "won't": 0.35; 'received:209.85': 0.35; 'but': 0.36; 'programmers': 0.36; 'subject:with': 0.36; 'subject: (': 0.36; 'why': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'think': 0.40; 'free': 0.61; 'different': 0.63; 'cobol': 0.84; 'conditions,': 0.84; 'besides,': 0.93 Newsgroups: comp.lang.python Date: Wed, 26 Sep 2012 15:53:40 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=123.192.32.215; posting-account=5JdMBQoAAABHnS4mjpqEzxnmWtgiiVNw References: <7x7grgtq75.fsf@ruckus.brouhaha.com> <4657ccef-b910-4781-9ea8-005b4e15f219@googlegroups.com> User-Agent: G2/1.0 X-Google-Web-Client: true X-Google-IP: 123.192.32.215 MIME-Version: 1.0 Subject: Re: using "*" to make a list of lists with repeated (and independent) elements From: 88888 Dihedral To: comp.lang.python@googlegroups.com Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Cc: python-list@python.org, 88888 Dihedral X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Message-ID: Lines: 64 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1348700023 news.xs4all.nl 6883 [2001:888:2000:d::a6]:51603 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:30246 Tim Chase=E6=96=BC 2012=E5=B9=B49=E6=9C=8827=E6=97=A5=E6=98=9F=E6=9C=9F=E5= =9B=9BUTC+8=E4=B8=8A=E5=8D=886=E6=99=8244=E5=88=8642=E7=A7=92=E5=AF=AB=E9= =81=93=EF=BC=9A > On 09/26/12 17:28, 88888 Dihedral wrote: >=20 > > 88888 Dihedral=E6=96=BC 2012=E5=B9=B49=E6=9C=8827=E6=97=A5=E6=98=9F=E6= =9C=9F=E5=9B=9BUTC+8=E4=B8=8A=E5=8D=886=E6=99=8207=E5=88=8635=E7=A7=92=E5= =AF=AB=E9=81=93=EF=BC=9A >=20 > >>>> In these conditions, how to make this list [[0,0,0],[0,0,0]] with "*= "=20 >=20 > >>>> without this behavior? >=20 > >>> >>> a =3D [[0]*3 for i in xrange(2)] >=20 > >>> >>> a[0][0]=3D2 >=20 > >>> >>> a >=20 > >>> [[2, 0, 0], [0, 0, 0]] >=20 > >=20 >=20 > > def zeros(m,n): >=20 > > a=3D[] >=20 > > for i in xrange(m): >=20 > > a.append([0]*n) >=20 > > return a >=20 > >=20 >=20 > > If one wants to tranlate to C, this is the style. >=20 >=20 >=20 > But this is Python, so why the heck would anybody want to emulate >=20 > *C* style? It could also be written in an assembly-language style, >=20 > COBOL style, or a Fortran style...none of which are particularly >=20 > valuable. >=20 >=20 >=20 > Besides, a C-style would allocate a single array of M*N slots and >=20 > then calculate 2d offsets into that single array. :-P >=20 >=20 >=20 > -tkc I don't think a lot programmers can write assembly programs well for different instruction sets of cpus. Of course if GCC was not supportd in manny platforms free=20 of charge, then I won't recommend this style of=20 programming in python.