Re: returning a list: IndexError

2005-03-31 Thread Steven Bethard
[EMAIL PROTECTED] wrote: Thats right. I wanted c1 and c2 to retrieve the values returned by t1 and t2 . Values for t1 and t2 could be anything. Also tbl is global. Then you need to return t1 and t2 in test, e.g.: py> import numarray as na py> tbl = na.zeros((32, 16)) py> def test(): ... t1 = 0x

Re: returning a list: IndexError

2005-03-31 Thread shama . bell
Thats right. I wanted c1 and c2 to retrieve the values returned by t1 and t2 . Values for t1 and t2 could be anything. Also tbl is global. -SB -- http://mail.python.org/mailman/listinfo/python-list

Re: returning a list: IndexError

2005-03-30 Thread Steven Bethard
[EMAIL PROTECTED] wrote: Steven Bethard wrote: py> import numarray as na py> tbl = na.zeros((32, 16)) py> def get_value(): ... data = test() ... c1 = data[0] ... c2 = data[1] ... print tbl[c1, c2] ... py> def test(): ... t1 = 0x0 ... t2 = 0x1 ... return tbl[t1, t2] ... p

Re: returning a list: IndexError

2005-03-30 Thread shama . bell
Steven Bethard wrote: > [EMAIL PROTECTED] wrote: > > from Numeric import * > > > > # Initialize the 32x16 global array to zeros > > tbl = zeros((32, 16) > > > > def getValue( value): > > data = test(value) > > c1 = data[0] > > c2 = data[1] > > print tbl[c1, c2] > > > > def test( va

returning a list: IndexError

2005-03-30 Thread shama . bell
Hello, I am getting the following error when returning a list: return tbl[c1,c2] "IndexError: each subindex must be either a slice, an integer, Ellipsis, or NewAxis" What does it mean? Here's the code snippet from Numeric import * # Initialize the 32x16 global array to zeros tbl = zeros(

Re: returning a list: IndexError

2005-03-30 Thread Steven Bethard
[EMAIL PROTECTED] wrote: from Numeric import * # Initialize the 32x16 global array to zeros tbl = zeros((32, 16) def getValue( value): data = test(value) c1 = data[0] c2 = data[1] print tbl[c1, c2] def test( value): t1 = 0x0 t2 = 0x1 return tbl[t1, t2] In test, tbl[0x0,

Re: list IndexError

2004-12-27 Thread Alex Martelli
Scott David Daniels <[EMAIL PROTECTED]> wrote: > Ishwor wrote: > > On Thu, 23 Dec 2004 13:57:55 -0300, Batista, Facundo > > <[EMAIL PROTECTED]> wrote: > >>#- True, true. Maybe you could lobby for copy as a builtin in > >>#- Python 3000? > >> > >>That's a good idea to me. But copy() as a builtin

Re: list IndexError

2004-12-26 Thread Scott David Daniels
Ishwor wrote: On Thu, 23 Dec 2004 13:57:55 -0300, Batista, Facundo <[EMAIL PROTECTED]> wrote: #- True, true. Maybe you could lobby for copy as a builtin in #- Python 3000? That's a good idea to me. But copy() as a builtin is not clear if it's shallow or deep. IMHO its preferable to use shallow

Re: list IndexError

2004-12-23 Thread Jeff Shannon
Grant Edwards wrote: On 2004-12-23, Steven Bethard <[EMAIL PROTECTED]> wrote: Ah, my mistake, I missed the [:] after the source argument that was taking a copy... which brings up the question, how many other people would miss it? Too many. This is why I greatly prefer list(lst) T

copying builtin types (WAS: list IndexError)

2004-12-23 Thread Steven Bethard
Grant Edwards wrote: I would have guessed that calling list() on a list was a noop. I would be wrong. Surprised, but wrong. I guess it's probably worth pointing out that most builtin mutable types can be copied using the type constructor: py> def check(obj): ... copy = type(obj)(obj) ...

Re: list IndexError

2004-12-23 Thread Ishwor
On Thu, 23 Dec 2004 13:57:55 -0300, Batista, Facundo <[EMAIL PROTECTED]> wrote: > > > [Steven Bethard] > > #- True, true. Maybe you could lobby for copy as a builtin in > #- Python 3000? > > That's a good idea to me. But copy() as a builtin is not clear if it's > shallow or deep. IMHO its

RE: list IndexError

2004-12-23 Thread Batista, Facundo
Title: RE: list IndexError [Steven Bethard] #- True, true.  Maybe you could lobby for copy as a builtin in #- Python 3000? That's a good idea to me. But copy() as a builtin is not clear if it's shallow or deep. .

Re: list IndexError

2004-12-23 Thread Steven Bethard
Grant Edwards wrote: Wouldn't the clearest way to get a copy would be to do something like: copy(lst) # I still think copy.copy() is a bit verbose... True, true. Maybe you could lobby for copy as a builtin in Python 3000? Steve -- http://mail.python.org/mailman/listinfo/python-list

Re: list IndexError

2004-12-23 Thread Grant Edwards
On 2004-12-23, Steven Bethard <[EMAIL PROTECTED]> wrote: >> Ah, my mistake, I missed the [:] after the source argument >> that was taking a copy... which brings up the question, how >> many other people would miss it? > > Too many. This is why I greatly prefer > > list(lst) To me, that's jus

Re: list IndexError

2004-12-23 Thread Steven Bethard
Mike C. Fletcher wrote: Ah, my mistake, I missed the [:] after the source argument that was taking a copy... which brings up the question, how many other people would miss it? Too many. This is why I greatly prefer list(lst) to lst[:] It's also clearer to me. Do I really want a "slice" of

Re: list IndexError

2004-12-23 Thread Steve Holden
M.E.Farmer wrote: Hello Ishwor , The simpliest way I can explain slicing is that the slices point to the spot *between* the items.. Take this list for example slicer = [0,1,2,3,4,5] slicer [1] 1 slicer [1:2] [1] slicer [:-1] [0,1,2,3,4] slicer[2,4] [2,3] You can also use a "stride" rather t

Re: list IndexError

2004-12-23 Thread Steven Bethard
Steven Bethard wrote: Ishwor wrote: i am trying to remove an item 'e' from the list l I thought it might be helpful to code some of the alternatives you've been given and look at the timings to put things into perspective. Corrected timings[1] using: $ python -m timeit -s "import remove" "remove.

Re: list IndexError

2004-12-23 Thread Mike C. Fletcher
Fredrik Lundh wrote: Mike C. Fletcher wrote: yeah actually i saw what Fedrik had to say above. I created a sliced copy of the l & did my homework within the for loop You might want to check it again before you hand it in ;) ... ... that's not the code he quoted in the mail you replie

Re: list IndexError

2004-12-23 Thread Nick Coghlan
Peter Otten wrote: I do not think it measures what you think it measures. Ah, good point. . . so we were actually measuring how long it takes to make zero replacements on the modified list, which explains the downward trend of the timings (as the modified list gets shorter). Adding the list copy

Re: list IndexError

2004-12-23 Thread Nick Coghlan
Steven Bethard wrote: Ishwor wrote: i am trying to remove an item 'e' from the list l I thought it might be helpful to code some of the alternatives you've been given and look at the timings to put things into perspective. The code: remove.py def remov

Re: list IndexError

2004-12-23 Thread Peter Otten
Steven Bethard wrote: > I thought it might be helpful to code some of the alternatives you've > been given and look at the timings to put things into perspective. The > code: > > remove.py > def remove_lc(x, lst): > lst[:] = [item for item in lst if

Re: list IndexError

2004-12-22 Thread Ishwor
On Thu, 23 Dec 2004 08:35:57 +0100, Fredrik Lundh <[EMAIL PROTECTED]> wrote: > Mike C. Fletcher wrote: > > >>yeah actually i saw what Fedrik had to say above. I created a sliced > >>copy of the l & did my homework within the for loop > >> > > You might want to check it again before you hand it in

Re: list IndexError

2004-12-22 Thread Fredrik Lundh
Mike C. Fletcher wrote: >>yeah actually i saw what Fedrik had to say above. I created a sliced >>copy of the l & did my homework within the for loop >> > You might want to check it again before you hand it in ;) ... > > >>> def ishwor( source ): > ... for item in source: > ... if item

Re: list IndexError

2004-12-22 Thread Mike C. Fletcher
Ishwor wrote: ... I believe lamda's are unnamed functions aren't they?? Still learning... ;-) Yes. yeah actually i saw what Fedrik had to say above. I created a sliced copy of the l & did my homework within the for loop You might want to check it again before you hand it in ;) ... >>> def ish

Re: list IndexError

2004-12-22 Thread M.E.Farmer
Hello Ishwor , The simpliest way I can explain slicing is that the slices point to the spot *between* the items.. Take this list for example slicer = [0,1,2,3,4,5] >>> slicer [1] 1 >>> slicer [1:2] [1] >>> slicer [:-1] [0,1,2,3,4] >>> slicer[2,4] [2,3] Hth, M.E.Farmer -- http://mail.pyth

Re: list IndexError

2004-12-22 Thread Ishwor
On Wed, 22 Dec 2004 21:42:16 GMT, Steven Bethard <[EMAIL PROTECTED]> wrote: > Ishwor wrote: > > i am trying to remove an item 'e' from the list l > > I thought it might be helpful to code some of the alternatives you've > been given and look at the timings to put things into perspective. The > co

Re: list IndexError

2004-12-22 Thread Steven Bethard
Ishwor wrote: i am trying to remove an item 'e' from the list l I thought it might be helpful to code some of the alternatives you've been given and look at the timings to put things into perspective. The code: remove.py def remove_lc(x, lst): lst[:

Re: list IndexError

2004-12-22 Thread Ishwor
On Thu, 23 Dec 2004 07:27:52 +1000, Egor Bolonev <[EMAIL PROTECTED]> wrote: > On Thu, 23 Dec 2004 06:56:02 +1030, Ishwor <[EMAIL PROTECTED]> wrote: > > l > > ['a', 'b', 'c', 'd', 'e'] > for x in l[:]: > >if x == 'd': > >l.remove('d'); > > > l > > ['a', 'b', '

Re: list IndexError

2004-12-22 Thread Egor Bolonev
On Thu, 23 Dec 2004 06:56:02 +1030, Ishwor <[EMAIL PROTECTED]> wrote: l ['a', 'b', 'c', 'd', 'e'] for x in l[:]: if x == 'd': l.remove('d'); l ['a', 'b', 'c', 'e'] This code is so clean and looks very healthy. Python will live a long way because its a cute language. imho the

Re: list IndexError

2004-12-22 Thread Ishwor
On Wed, 22 Dec 2004 14:59:32 -0500, Mike C. Fletcher <[EMAIL PROTECTED]> wrote: [snip] > > Probably the most pythonic approach to this problem when dealing with > small lists is this: > >result = [ item for item in source if item != 'e' ] > > or, if you're using an older version of Python wit

Re: list IndexError

2004-12-22 Thread Mike C. Fletcher
Ishwor wrote: i am trying to remove an item 'e' from the list l but i keep getting IndexError. I know the size of the list l is changing in the for loop & its sort of trivial task but i found no other way than to suppress the IndexError by doing a pass. any other ways you guys can suggest? Also is

Re: list IndexError

2004-12-22 Thread Fredrik Lundh
"Ishwor" <[EMAIL PROTECTED]> wrote: > i am trying to remove an item 'e' from the list l but i keep getting > IndexError. > I know the size of the list l is changing in the for loop & its sort > of trivial task but i found no other way than to suppress the > IndexError by doing a pass. any other w

list IndexError

2004-12-22 Thread Ishwor
i am trying to remove an item 'e' from the list l but i keep getting IndexError. I know the size of the list l is changing in the for loop & its sort of trivial task but i found no other way than to suppress the IndexError by doing a pass. any other ways you guys can suggest? Also is this a good or