Re: Simple Problem but tough for me if i want it in linear time

2010-08-30 Thread Aahz
In article , Tim Chase wrote: >On 08/18/10 21:47, Steven D'Aprano wrote: >> >> Frankly, I think the OP doesn't really know what he wants, other than >> premature optimization. It's amazing how popular that is :) > >You see, the trick to prematurely optimizing is to have a good >algorithm for pre

Re: Simple Problem but tough for me if i want it in linear time

2010-08-18 Thread Tim Chase
On 08/18/10 21:47, Steven D'Aprano wrote: Frankly, I think the OP doesn't really know what he wants, other than premature optimization. It's amazing how popular that is :) You see, the trick to prematurely optimizing is to have a good algorithm for prematurely optimizing...the real question th

Re: Simple Problem but tough for me if i want it in linear time

2010-08-18 Thread Steven D'Aprano
On Wed, 18 Aug 2010 16:03:58 +0200, Frederic Rentsch wrote: > On Mon, 2010-08-16 at 23:17 +, Steven D'Aprano wrote: >> On Mon, 16 Aug 2010 20:40:52 +0200, Frederic Rentsch wrote: >> >> > How about >> > >> [obj for obj in dataList if obj.number == 100] >> > >> > That should create a lis

Re: Simple Problem but tough for me if i want it in linear time

2010-08-18 Thread Frederic Rentsch
On Mon, 2010-08-16 at 23:17 +, Steven D'Aprano wrote: > On Mon, 16 Aug 2010 20:40:52 +0200, Frederic Rentsch wrote: > > > How about > > > [obj for obj in dataList if obj.number == 100] > > > > That should create a list of all objects whose .number is 100. No need > > to cycle through a

Re: Simple Problem but tough for me if i want it in linear time

2010-08-16 Thread Steven D'Aprano
On Mon, 16 Aug 2010 20:40:52 +0200, Frederic Rentsch wrote: > How about > [obj for obj in dataList if obj.number == 100] > > That should create a list of all objects whose .number is 100. No need > to cycle through a loop. What do you think the list comprehension does, if not cycle throug

Re: Simple Problem but tough for me if i want it in linear time

2010-08-16 Thread Frederic Rentsch
On Sun, 2010-08-15 at 15:14 +0200, Peter Otten wrote: > ChrisChia wrote: > > > dataList = [a, b, c, ...] > > where a, b, c are objects of a Class X. > > In Class X, it contains self.name and self.number > > > > If i wish to test whether a number (let's say 100) appears in one of > > the object, a

Re: Simple Problem but tough for me if i want it in linear time

2010-08-15 Thread Steven D'Aprano
On Sun, 15 Aug 2010 05:47:04 -0700, ChrisChia wrote: > dataList = [a, b, c, ...] > where a, b, c are objects of a Class X. In Class X, it contains > self.name and self.number > > If i wish to test whether a number (let's say 100) appears in one of the > object, and return that object, > is that o

Re: Simple Problem but tough for me if i want it in linear time

2010-08-15 Thread MRAB
ChrisChia wrote: dataList = [a, b, c, ...] where a, b, c are objects of a Class X. In Class X, it contains self.name and self.number If i wish to test whether a number (let's say 100) appears in one of the object, and return that object, is that only fast way of solving this problem without iter

Re: Simple Problem but tough for me if i want it in linear time

2010-08-15 Thread Peter Otten
ChrisChia wrote: > dataList = [a, b, c, ...] > where a, b, c are objects of a Class X. > In Class X, it contains self.name and self.number > > If i wish to test whether a number (let's say 100) appears in one of > the object, and return that object, > is that only fast way of solving this problem

Re: simple problem with lists I am just forgetting

2008-07-31 Thread Paul McGuire
On Jul 31, 2:51 pm, Alexnb <[EMAIL PROTECTED]> wrote: > Lets say we have this list: > > funlist = ['a', 'b', 'c'] > > and lets say I do this: > > if funlist[4]: >     print funlist[4] > > I will get the exception "list index out of range" > > How can I test if the list item is empty without getting

Re: simple problem with lists I am just forgetting

2008-07-31 Thread bearophileHUGS
Alexnb: > How can I test if the list item is empty without getting that exception? In Python such list cell isn't empty, it's absent. So you can use len(somelist) to see how much long the list is before accessing its items. Often you can iterate on the list with a for, so you don't need to care of

Re: Simple problem with GUI!!

2006-10-27 Thread Fredrik Lundh
"mohan" wrote: > At the end I had to close down my entire python compiler. I am using > Python compiler with following specs in Windows XP OS. > > Pythonwin - Python IDE and GUI Framework for Windows. > PythonWin 2.2.1 (#34, Feb 25 2003, 11:29:09) [MSC 32 bit (Intel)] on > win32. > Portions Copyri

Re: simple problem with os.rename() parameters - path with spaces

2005-09-10 Thread Peter Hansen
Tom wrote: > Peter Hansen wrote: >> Where do you think those double quotation marks came from? What >> happens if you try the following instead of using the variables you >> were trying to use? >> >> os.rename("e:\\music\\Joni Mitchell\\ogg-8", >> "e:\\music.ogg\\Joni Mitchell\\ogg-8") >> >

Re: simple problem with os.rename() parameters - path with spaces

2005-09-10 Thread Tom
Peter Hansen wrote: > Tom wrote: > >>Drive E: is removable, so I was careful to verify that that was a factor >>in the problem. >> >>Yes, I can do the same renaming, with the same drive, at the command line. >> >>I think I put the emphasis in the wrong place in my question. This >>isn't really

Re: simple problem with os.rename() parameters - path with spaces

2005-09-10 Thread Peter Hansen
Tom wrote: > Drive E: is removable, so I was careful to verify that that was a factor > in the problem. > > Yes, I can do the same renaming, with the same drive, at the command line. > > I think I put the emphasis in the wrong place in my question. This > isn't really about os.rename(). It is

Re: simple problem with os.rename() parameters - path with spaces

2005-09-10 Thread Tom
Yes, I am sure about those things. I've tried shutil.move and got the same result. Forward slash? I'll give that a try and report back here if it works. Thanks, Tom. Larry Bates wrote: > Are you sure the source directory exists and you > have rights to rename it? Because the rename works > for

Re: simple problem with os.rename() parameters - path with spaces

2005-09-10 Thread Tom
Peter Hansen wrote: > Tom wrote: > >>I'm having a problem using a path with spaces as a parameter to >>os.rename() in a program on WinXP. >> >>This works fine at the command line (where the folder "c:\aa bb" exists) >> >> > os.rename( "c\aa bb", "c:\cc dd" ); >> > >> >>But, I can't get it to work

Re: simple problem with os.rename() parameters - path with spaces

2005-09-09 Thread Peter Hansen
Tom wrote: > I'm having a problem using a path with spaces as a parameter to > os.rename() in a program on WinXP. > > This works fine at the command line (where the folder "c:\aa bb" exists) > > > os.rename( "c\aa bb", "c:\cc dd" ); > > > > But, I can't get it to work in my program, eg. > >

Re: simple problem with os.rename() parameters - path with spaces

2005-09-09 Thread Larry Bates
Are you sure the source directory exists and you have rights to rename it? Because the rename works for me. But you may want to look at shutil.move and/or use forward slashes (they work under Windows) -Larry Bates Tom wrote: > I'm having a problem using a path with spaces as a parameter to > o

Re: Simple Problem

2005-07-24 Thread ncf
Thank you all for your replies. The repr() solution wasn't exactly what I was looking for, as I wasn't planning on eval()ing it, but the (en|de)code solution was exactly what I was looking for. An extended thanks to Jp for informing me of the version compatibility :) Have a GREAT day :) -Wes --

Re: Simple Problem

2005-07-24 Thread Jp Calderone
On 24 Jul 2005 18:14:13 -0700, ncf <[EMAIL PROTECTED]> wrote: >I know I've seen this somewhere before, but does anyone know what the >function to escape a string is? (i.e., encoding newline to "\n" and a >chr(254) to "\xfe") (and visa-versa) > >Thanks for helping my ignorance :P Python 2.4.1 (

Re: Simple Problem

2005-07-24 Thread Robert Kern
ncf wrote: > I know I've seen this somewhere before, but does anyone know what the > function to escape a string is? (i.e., encoding newline to "\n" and a > chr(254) to "\xfe") (and visa-versa) In [1]: s = "foo\n\xfe" In [2]: s.encode("string_escape") Out[2]: 'foo\\n\\xfe' In [3]: repr(s)[1:-1]

Re: Simple Problem

2005-07-24 Thread Paul Rubin
"ncf" <[EMAIL PROTECTED]> writes: > I know I've seen this somewhere before, but does anyone know what the > function to escape a string is? (i.e., encoding newline to "\n" and a > chr(254) to "\xfe") (and visa-versa) repr(s) -- http://mail.python.org/mailman/listinfo/python-list

Re: Simple Problem

2005-07-24 Thread Cyril Bazin
By any chance are you speaking about the function "repr" ? Cyril On 24 Jul 2005 18:14:13 -0700, ncf <[EMAIL PROTECTED]> wrote: I know I've seen this somewhere before, but does anyone know what thefunction to escape a string is? (i.e., encoding newline to "\n" and achr(254) to "\xfe") (and visa-vers