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


Groups > comp.lang.python > #30327

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

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!news.mixmin.net!feed.xsnews.nl!border-1.ams.xsnews.nl!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <dihedral88888@googlemail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.002
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'python,': 0.02; 'emulate': 0.07; '[0,': 0.09; 'array.': 0.09; 'references.': 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; 'offsets': 0.16; 'wrote:': 0.17; 'tim': 0.18; '>>>': 0.18; 'subject:) ': 0.20; 'written': 0.20; '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; 'subject:lists': 0.32; 'could': 0.32; 'print': 0.32; 'received:google.com': 0.34; 'list': 0.35; 'clear': 0.35; 'from:addr:googlemail.com': 0.35; 'received:209.85': 0.35; 'but': 0.36; 'subject:with': 0.36; 'subject: (': 0.36; 'why': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'situation': 0.62; 'cobol': 0.84; 'conditions,': 0.84; 'received:209.85.213.184': 0.91; 'received:mail- yx0-f184.google.com': 0.91; 'besides,': 0.93
Newsgroups comp.lang.python
Date Thu, 27 Sep 2012 14:24:00 -0700 (PDT)
In-Reply-To <mailman.1461.1348699454.27098.python-list@python.org>
Complaints-To groups-abuse@google.com
Injection-Info glegroupsg2000goo.googlegroups.com; posting-host=123.192.32.215; posting-account=5JdMBQoAAABHnS4mjpqEzxnmWtgiiVNw
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> <mailman.1461.1348699454.27098.python-list@python.org>
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 <dihedral88888@googlemail.com>
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 <dihedral88888@googlemail.com>
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>
Message-ID <mailman.1516.1348781049.27098.python-list@python.org> (permalink)
Lines 65
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1348781049 news.xs4all.nl 6872 [2001:888:2000:d::a6]:54006
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:30327

Show key headers only | View raw


Tim Chase於 2012年9月27日星期四UTC+8上午6時44分42秒寫道:
> 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

a=[1, 2,3] 
b=[a]*4
print b 
a[1]=4
print b

I thnik this is very clear about the situation in entangled references.

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