Re: [Tutor] List indexing problem

2008-07-26 Thread Dave Kuhlman
On Sat, Jul 26, 2008 at 03:08:45AM -0400, Kent Johnson wrote: > On Fri, Jul 25, 2008 at 7:35 PM, Mike Meisner <[EMAIL PROTECTED]> wrote: > > Do you happen to know if there is an efficient way to initialize a list > > like this without explicitly writing out each element? > > You can make a copy o

Re: [Tutor] List indexing problem

2008-07-26 Thread Kent Johnson
On Fri, Jul 25, 2008 at 8:20 PM, Michiel Overtoom <[EMAIL PROTECTED]> wrote: > Mike wrote... > >>Do you happen to know if there is an efficient way to initialize a list >>like this without explicitly writing out each element? > temp = [[0, 0, 0],[0, 0, 0],[0, 0, 0]] print temp > [[0, 0,

Re: [Tutor] List indexing problem

2008-07-26 Thread Kent Johnson
On Fri, Jul 25, 2008 at 7:35 PM, Mike Meisner <[EMAIL PROTECTED]> wrote: > Do you happen to know if there is an efficient way to initialize a list > like this without explicitly writing out each element? You can make a copy of the inner list each time through the loop: IP = [] temp = [[0,

Re: [Tutor] List indexing problem

2008-07-25 Thread Lie Ryan
On Sat, 2008-07-26 at 02:20 +0200, [EMAIL PROTECTED] wrote: > Message: 8 > Date: Fri, 25 Jul 2008 19:35:54 -0400 > From: "Mike Meisner" <[EMAIL PROTECTED]> > Subject: Re: [Tutor] List indexing problem > To: "Steve Willoughby" <[EMAIL PROTECTED]&g

Re: [Tutor] List indexing problem

2008-07-25 Thread Michiel Overtoom
Mike wrote... >Do you happen to know if there is an efficient way to initialize a list >like this without explicitly writing out each element? >>> temp = [[0, 0, 0],[0, 0, 0],[0, 0, 0]] >>> print temp [[0, 0, 0], [0, 0, 0], [0, 0, 0]] >>> print [[0]*3]*3 [[0, 0, 0], [0, 0, 0], [0, 0, 0]] --

Re: [Tutor] List indexing problem

2008-07-25 Thread Mike Meisner
ED]> To: "Mike Meisner" <[EMAIL PROTECTED]> Cc: Sent: Friday, July 25, 2008 7:03 PM Subject: Re: [Tutor] List indexing problem Mike Meisner wrote: I need to do some statistical analysis by binning values into an array. Being new to Python, I tried to use a list of lists. I&#x

Re: [Tutor] List indexing problem

2008-07-25 Thread Alan Gauld
"Mike Meisner" <[EMAIL PROTECTED]> wrote def testanalysis(): IP = [] temp = [[0, 0, 0],[0, 0, 0],[0, 0, 0]] # initialize to zero for i in range(20): IP.append(temp) this appends the same list (temp) 20 times. So when you change the list it is reflected 20 times. Lists hold

Re: [Tutor] List indexing problem

2008-07-25 Thread Steve Willoughby
Mike Meisner wrote: I need to do some statistical analysis by binning values into an array. Being new to Python, I tried to use a list of lists. I've extracted just the minimum code that I'm having trouble with: What you need to remember is that Python works with *objects*, and variables a