Re: Pythonic way to determine if one char of many in a string

2009-02-21 Thread odeits
On Feb 21, 2:24 pm, rdmur...@bitdance.com wrote: > odeits wrote: > > On Feb 21, 12:47=A0am, "Gabriel Genellina" > > wrote: > > > En Sat, 21 Feb 2009 01:14:02 -0200, odeits escribi=F3: > > > > > On Feb 15, 11:31=A0pm, odeits wrote: > > > >> It seems what you are actually testing for is if the in

Re: Pythonic way to determine if one char of many in a string

2009-02-21 Thread rdmurray
odeits wrote: > On Feb 21, 12:47=A0am, "Gabriel Genellina" > wrote: > > En Sat, 21 Feb 2009 01:14:02 -0200, odeits escribi=F3: > > > > > On Feb 15, 11:31=A0pm, odeits wrote: > > >> It seems what you are actually testing for is if the intersection of > > >> the two sets is not empty where the fi

Re: Pythonic way to determine if one char of many in a string

2009-02-21 Thread odeits
On Feb 21, 12:47 am, "Gabriel Genellina" wrote: > En Sat, 21 Feb 2009 01:14:02 -0200, odeits escribió: > > > > > On Feb 15, 11:31 pm, odeits wrote: > >> It seems what you are actually testing for is if the intersection of > >> the two sets is not empty where the first set is the characters in >

Re: Pythonic way to determine if one char of many in a string

2009-02-21 Thread Gabriel Genellina
En Sat, 21 Feb 2009 01:14:02 -0200, odeits escribió: On Feb 15, 11:31 pm, odeits wrote: It seems what you are actually testing for is if the intersection of the two sets is not empty where the first set is the characters in your word and the second set is the characters in your defined strin

Re: Pythonic way to determine if one char of many in a string

2009-02-20 Thread odeits
On Feb 15, 11:31 pm, odeits wrote: > On Feb 15, 9:56 pm, Chris Rebert wrote: > > > > > On Sun, Feb 15, 2009 at 9:17 PM,   wrote: > > > I need to test strings to determine if one of a list of chars is in the > > > string. A simple example would be to test strings to determine if they > > > have >

Re: Pythonic way to determine if one char of many in a string

2009-02-19 Thread Martin P. Hellwig
MRAB wrote: Dennis Lee Bieber wrote: On Wed, 18 Feb 2009 21:22:45 +0100, Peter Otten <__pete...@web.de> declaimed the following in comp.lang.python: Steve Holden wrote: Jervis Whitley wrote: What happens when you have hundreds of megabytes, I don't know. I hope I never have to test a wor

Re: Pythonic way to determine if one char of many in a string

2009-02-19 Thread MRAB
Dennis Lee Bieber wrote: On Wed, 18 Feb 2009 21:22:45 +0100, Peter Otten <__pete...@web.de> declaimed the following in comp.lang.python: Steve Holden wrote: Jervis Whitley wrote: What happens when you have hundreds of megabytes, I don't know. I hope I never have to test a word that is hun

Re: Pythonic way to determine if one char of many in a string

2009-02-19 Thread John Machin
On Feb 19, 6:47 pm, Dennis Lee Bieber wrote: > On Wed, 18 Feb 2009 21:22:45 +0100, Peter Otten <__pete...@web.de> > declaimed the following in comp.lang.python: > > > Steve Holden wrote: > > > > Jervis Whitley wrote: > > >>> What happens when you have hundreds of megabytes, I don't know. > > > >>

Re: Pythonic way to determine if one char of many in a string

2009-02-18 Thread Peter Otten
Steve Holden wrote: > Jervis Whitley wrote: >>> What happens when you have hundreds of megabytes, I don't know. >>> >>> >> I hope I never have to test a word that is hundreds of megabytes long >> for a vowel :) > > I see you don't speak German ;-) I tried to come up with a funny way to point out

Re: Pythonic way to determine if one char of many in a string

2009-02-18 Thread Peter Otten
Steven D'Aprano wrote: > On Wed, 18 Feb 2009 07:08:04 +1100, Jervis Whitley wrote: > > >>> This moves the for-loop out of slow Python into fast C and should be >>> much, much faster for very large input. >>> >>> >> _Should_ be faster. > > Yes, Python's timing results are often unintuitive. Ind

Re: Pythonic way to determine if one char of many in a string

2009-02-18 Thread Steve Holden
Jervis Whitley wrote: >> What happens when you have hundreds of megabytes, I don't know. >> >> > I hope I never have to test a word that is hundreds of megabytes long > for a vowel :) I see you don't speak German ;-) -- Steve Holden+1 571 484 6266 +1 800 494 3119 Holden Web LLC

Re: Pythonic way to determine if one char of many in a string

2009-02-18 Thread Jervis Whitley
> > What happens when you have hundreds of megabytes, I don't know. > > I hope I never have to test a word that is hundreds of megabytes long for a vowel :) -- http://mail.python.org/mailman/listinfo/python-list

Re: Pythonic way to determine if one char of many in a string

2009-02-18 Thread Steven D'Aprano
On Wed, 18 Feb 2009 07:08:04 +1100, Jervis Whitley wrote: >> This moves the for-loop out of slow Python into fast C and should be >> much, much faster for very large input. >> >> > _Should_ be faster. Yes, Python's timing results are often unintuitive. > Here is my test on an XP system Python

Re: Pythonic way to determine if one char of many in a string

2009-02-17 Thread Jervis Whitley
> > This moves the for-loop out of slow Python into fast C and should be much, > much faster for very large input. > _Should_ be faster. Here is my test on an XP system Python 2.5.4. I had similar results on python 2.7 trunk. WORD = 'g' * 100 WORD2 = 'g' * 50 + 'U' BIGWORD = 'g' * 1 + 'U'

Re: Pythonic way to determine if one char of many in a string

2009-02-17 Thread Steven D'Aprano
Nicolas Dandrimont wrote: > I would go for something like: > > for char in word: > if char in 'aeiouAEIUO': > char_found = True > break > else: > char_found = False > > (No, I did not forget to indent the else statement, see > http://docs.python.org/reference/compound_stm

Re: Pythonic way to determine if one char of many in a string

2009-02-16 Thread Stefaan Himpe
An entirely different approach would be to use a regular expression: import re if re.search("[abc]", "nothing expekted"): print "a, b or c occurs in the string 'nothing expekted'" if re.search("[abc]", "something expected"): print "a, b or c occurs in the string 'something expected'" Best

Re: Pythonic way to determine if one char of many in a string

2009-02-16 Thread J. Cliff Dyer
On Mon, 2009-02-16 at 00:28 -0500, Nicolas Dandrimont wrote: > * pyt...@bdurham.com [2009-02-16 00:17:37 -0500]: > > > I need to test strings to determine if one of a list of chars is > > in the string. A simple example would be to test strings to > > determine if they have a vowel (aeiouAEIOU)

Re: Pythonic way to determine if one char of many in a string

2009-02-16 Thread Nicolas Dandrimont
* pyt...@bdurham.com [2009-02-16 00:48:34 -0500]: > Nicolas, > > > I would go for something like: > > > > for char in word: > > if char in 'aeiouAEIUO': > > char_found = True > > break > > else: > > char_found = False > > > > It is clear (imo), and it is seems to be the

Re: Pythonic way to determine if one char of many in a string

2009-02-15 Thread odeits
On Feb 15, 9:56 pm, Chris Rebert wrote: > On Sun, Feb 15, 2009 at 9:17 PM,   wrote: > > I need to test strings to determine if one of a list of chars is in the > > string. A simple example would be to test strings to determine if they have > > a vowel (aeiouAEIOU) present. > > > I was hopeful that

Re: Pythonic way to determine if one char of many in a string

2009-02-15 Thread Chris Rebert
On Sun, Feb 15, 2009 at 9:17 PM, wrote: > I need to test strings to determine if one of a list of chars is in the > string. A simple example would be to test strings to determine if they have > a vowel (aeiouAEIOU) present. > > I was hopeful that there was a built-in method that operated similar

Re: Pythonic way to determine if one char of many in a string

2009-02-15 Thread Nicolas Dandrimont
* pyt...@bdurham.com [2009-02-16 00:17:37 -0500]: > I need to test strings to determine if one of a list of chars is > in the string. A simple example would be to test strings to > determine if they have a vowel (aeiouAEIOU) present. > I was hopeful that there was a built-in method that operated

Re: Pythonic way to determine if one char of many in a string

2009-02-15 Thread python
Nicolas, > I would go for something like: > > for char in word: > if char in 'aeiouAEIUO': > char_found = True > break > else: > char_found = False > > It is clear (imo), and it is seems to be the intended idiom for a > search loop, that short-circuits as soon as a match