Python quesiton

Edward Glowacki glowack2@msu.edu
Sat, 3 Feb 2001 13:59:06 -0500 (EST)


On 3 Feb 2001, Jordan Katz wrote:
> Edward Glowacki <glowack2@msu.edu> writes:
> 
> > On Fri, 2 Feb 2001, Mark Szidik wrote:
> > > Is there a simple way to test a string to see if it holds numeric
> > > characters in python?   I can't seem to find anything simple.
> > 
> > *whips out the sledgehammer that is Python and prepares to hammer
> > out some code...*
> [snip solution w/regexps]
> 
> Here's a way to do it without using regular expressions.  The code
> uses string.digits, which I believe was defined for this purpose:
> 
> def with_numbers(s):
>   import string
>   for c in s:
>     if c in string.digits:
>       return 1
>   return 0


The code you have is basically a double nested for loop ("for c in s" and
an implied for loop in "if c in string.digits").  I'm not sure
without looking at the internals of Python, but it is my guess that
the compiled regexp search would process faster than the double
for loop.

-- 
Edward Glowacki			glowack2@msu.edu
Computer Laboratory, Technical Support Services		
Michigan State University