There's got to be an easy way to do this

Terry Reedy tjreedy at
Thu Jul 5 20:58:53 CEST 2001

"Emile van Sebille" <emile at> wrote in message
news:9i2c77$gmc74$1 at
> I'm not sure how you mean slower, but I tested just now to see, and this
> the fastest of the four.
> def str_join(iters):
>     for i in iters:
>         "".join([x for x in '(123)/456-7890' if x in '0123456789'])

This could use either conditional '0' <= x <= '9'  with 2 compares instead
of average 5.5
or x.isdigit() from below.
> def flt_lmbda(iters):
>     for i in iters:
>         filter(lambda c:c.isdigit(), '(123)/456-7890')

would two compares be faster than one func call?

TJ Reedy

More information about the Python-list mailing list