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


Groups > comp.lang.python > #30510

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

Newsgroups comp.lang.python
Date 2012-09-29 10:01 -0700
References (1 earlier) <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> <98034dee-0108-4099-bbdd-82f90e96d383@googlegroups.com>
Subject Re: using "*" to make a list of lists with repeated (and independent) elements
From 88888 Dihedral <dihedral88888@googlemail.com>
Message-ID <mailman.1641.1348938094.27098.python-list@python.org> (permalink)

Show all headers | View raw


On Saturday, September 29, 2012 9:46:22 PM UTC+8, Ramchandra Apte wrote:
> On Thursday, 27 September 2012 04:14:42 UTC+5:30, Tim Chase  wrote:
> 
> > 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
> 
> 
> 
> 88888 Dihedral is a bot.

Don't you get it why I avoided the lambda one liner as a functon. 

I prefer the def way with a name chosen.

 

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