There's got to be an easy way to do this (fwd)

Lulu of the Lotus-Eaters mertz at gnosis.cx
Thu Jul 5 14:55:40 EDT 2001


"Emile van Sebille" <emile at fenx.com> wrote
|I'm not sure how you mean slower, but I tested just now to see, and this is
|the fastest of the four.
|-   500-       std_re      cpl_re      str_join    flt_lmbda
|        50 :    3.74         3.60         0.70         0.75

FWIW, the version I presented was not my first thought.  I first wrote:

    def flt_lmbda2(iters):
        for i in iters:
            filter(lambda c:c in '0123456789', '(123)/456-7890')

But before I pressed the "send" button, the variant:

    def flt_lmbda(iters):
        for i in iters:
            filter(lambda c:c.isdigit(), '(123)/456-7890')

Seemed a bit more clear, and a few characters shorter.

However, applying timings with the first thought included gives:

-   500-       std_re      cpl_re      str_join    flt_lmbda   flt_lmbda2
         5 :    0.77         0.74         0.10         0.14         0.10
        10 :    1.54         1.50         0.21         0.29         0.19
        50 :    7.71         7.44         1.04         1.44         1.00

Which puts me back with a tiny speed advantage over all comers :-).
(But apparently with slower CPU than Emile... time to start saving).

Yours, Lulu...





More information about the Python-list mailing list