Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #30243

Re: using "*" to make a list of lists with repeated (and independent) elements

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 <python.list@tim.thechases.com>
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 <python.list@tim.thechases.com>
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 <dihedral88888@googlemail.com>
Subject Re: using "*" to make a list of lists with repeated (and independent) elements
References <b58cj9-h5d.ln1@rama.fbx.proxad.net> <7x7grgtq75.fsf@ruckus.brouhaha.com> <f7dd2519-4e27-4905-805e-1ecc0b06b06f@googlegroups.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 <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.1461.1348699454.27098.python-list@python.org> (permalink)
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

Show key headers only | View raw


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


Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

using "*" to make a list of lists with repeated (and independent) elements TP <TP@frenoespam.fr.invalid> - 2012-09-26 23:20 +0200
  Re: using "*" to make a list of lists with repeated (and independent) elements Ian Kelly <ian.g.kelly@gmail.com> - 2012-09-26 15:39 -0600
  Re: using "*" to make a list of lists with repeated (and independent) elements Paul Rubin <no.email@nospam.invalid> - 2012-09-26 14:43 -0700
    Re: using "*" to make a list of lists with repeated (and independent) elements 88888 Dihedral <dihedral88888@googlemail.com> - 2012-09-26 15:07 -0700
      Re: using "*" to make a list of lists with repeated (and independent) elements 88888 Dihedral <dihedral88888@googlemail.com> - 2012-09-26 15:28 -0700
        Re: using "*" to make a list of lists with repeated (and independent) elements Tim Chase <python.list@tim.thechases.com> - 2012-09-26 17:45 -0500
          Re: using "*" to make a list of lists with repeated (and independent) elements 88888 Dihedral <dihedral88888@googlemail.com> - 2012-09-26 15:53 -0700
          Re: using "*" to make a list of lists with repeated (and independent) elements 88888 Dihedral <dihedral88888@googlemail.com> - 2012-09-26 15:53 -0700
          Re: using "*" to make a list of lists with repeated (and independent) elements 88888 Dihedral <dihedral88888@googlemail.com> - 2012-09-27 14:24 -0700
          Re: using "*" to make a list of lists with repeated (and independent) elements 88888 Dihedral <dihedral88888@googlemail.com> - 2012-09-27 14:24 -0700
          Re: using "*" to make a list of lists with repeated (and independent) elements Ramchandra Apte <maniandram01@gmail.com> - 2012-09-29 06:46 -0700
            Re: using "*" to make a list of lists with repeated (and independent) elements 88888 Dihedral <dihedral88888@googlemail.com> - 2012-09-29 10:01 -0700
              Re: using "*" to make a list of lists with repeated (and independent) elements Ian Kelly <ian.g.kelly@gmail.com> - 2012-09-29 11:18 -0600
                Re: using "*" to make a list of lists with repeated (and independent) elements 88888 Dihedral <dihedral88888@googlemail.com> - 2012-09-29 11:50 -0700
                Re: using "*" to make a list of lists with repeated (and independent) elements 88888 Dihedral <dihedral88888@googlemail.com> - 2012-09-29 11:50 -0700
              Re: using "*" to make a list of lists with repeated (and independent) elements Chris Angelico <rosuav@gmail.com> - 2012-09-30 03:41 +1000
            Re: using "*" to make a list of lists with repeated (and independent) elements 88888 Dihedral <dihedral88888@googlemail.com> - 2012-09-29 10:01 -0700
          Re: using "*" to make a list of lists with repeated (and independent) elements Ramchandra Apte <maniandram01@gmail.com> - 2012-09-29 06:46 -0700
  Re: using "*" to make a list of lists with repeated (and independent) elements 88888 Dihedral <dihedral88888@googlemail.com> - 2012-09-26 14:45 -0700

csiph-web