Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!weretis.net!feeder1.news.weretis.net!news1.tnib.de!feed.news.tnib.de!news.tnib.de!newsfeed.freenet.ag!news2.euro.net!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; 'emulate': 0.07; '[0,': 0.09; 'array.': 0.09; 'subject:using': 0.09; 'cc:addr :python-list': 0.10; 'def': 0.10; '"*"': 0.16; '-tkc': 0.16; '0],': 0.16; ':-p': 0.16; 'from:addr:python.list': 0.16; 'from:addr:tim.thechases.com': 0.16; 'from:name:tim chase': 0.16; 'message-id:@tim.thechases.com': 0.16; 'offsets': 0.16; 'received:70.251': 0.16; 'received:dsl.rcsntx.swbell.net': 0.16; 'received:rcsntx.swbell.net': 0.16; 'received:swbell.net': 0.16; 'wrote:': 0.17; '>>>': 0.18; 'written': 0.20; 'cc:2**0': 0.23; 'cc:no real name:2**0': 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; 'subject:lists': 0.32; 'could': 0.32; 'list': 0.35; 'but': 0.36; 'subject:with': 0.36; 'subject: (': 0.36; 'why': 0.37; 'subject:: ': 0.38; 'cobol': 0.84; 'conditions,': 0.84; 'received:50.22': 0.84; 'besides,': 0.93 Date: Wed, 26 Sep 2012 17:45:19 -0500 From: Tim Chase User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.24) Gecko/20111120 Icedove/3.1.16 MIME-Version: 1.0 To: 88888 Dihedral Subject: Re: using "*" to make a list of lists with repeated (and independent) elements References: <7x7grgtq75.fsf@ruckus.brouhaha.com> <4657ccef-b910-4781-9ea8-005b4e15f219@googlegroups.com> In-Reply-To: <4657ccef-b910-4781-9ea8-005b4e15f219@googlegroups.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - boston.accountservergroup.com X-AntiAbuse: Original Domain - python.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tim.thechases.com X-Source: X-Source-Args: X-Source-Dir: Cc: python-list@python.org 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: , Newsgroups: comp.lang.python Message-ID: Lines: 29 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1348699454 news.xs4all.nl 6870 [2001:888:2000:d::a6]:48692 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:30243 On 09/26/12 17:28, 88888 Dihedral wrote: > 88888 Dihedral於 2012年9月27日星期四UTC+8上午6時07分35秒寫道: >>>> In these conditions, how to make this list [[0,0,0],[0,0,0]] with "*" >>>> without this behavior? >>> >>> a = [[0]*3 for i in xrange(2)] >>> >>> a[0][0]=2 >>> >>> a >>> [[2, 0, 0], [0, 0, 0]] > > def zeros(m,n): > a=[] > for i in xrange(m): > a.append([0]*n) > return a > > If one wants to tranlate to C, this is the style. But this is Python, so why the heck would anybody want to emulate *C* style? It could also be written in an assembly-language style, COBOL style, or a Fortran style...none of which are particularly valuable. Besides, a C-style would allocate a single array of M*N slots and then calculate 2d offsets into that single array. :-P -tkc