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

Quote:

>   filter(lambda c:c.isdigit(), '(123)/456-7890')
> Thir{*filter*} characters shorter than Emile's, and still no [re] :-).

|filter(string.isdigit, '(123)/456-7890')
|is six fewer characters and IMHO more readable still.

  >>> filter(string.isdigit, '(123)/456-7890')
  Traceback (most recent call last):
    File "<stdin>", line 1, in ?
  NameError: There is no variable named 'string'

Or did you expect me to "spend" 13 characters on 'import string'? :-)

Btw. Alex is quite right on his speedy solution:

  def AM_trans(iters):
      nondigits = ''.join([chr(x) for x in range(0,256) if not chr(x).isdigit()])
      identity = string.maketrans('','')
      for i in iters:
          '(123)/456-7890'.translate(identity, nondigits)

-   500-       str_join2   flt_lmbda3  traditional   AM_trans
         5 :    0.07         0.05         0.08         0.02
        10 :    0.15         0.11         0.16         0.06
        50 :    0.72         0.57         0.79         0.24

Yours, Lulu...



Tue, 23 Dec 2003 05:49:31 GMT  
 
 [ 1 post ] 

 Relevant Pages 

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

2. (Fwd) (Fwd) Re: Band Matrices

3. (Fwd) MESSAGE ON PHONE SCAM (fwd)

4. [Fwd: envienla (fwd)]

5. Fwd: [LogoForum] Re: (Fwd) [apcs] Karel Goes Fishing!

6. Fwd: NetRexx language now available (fwd)

7. [Fwd: Re: RubyInline 1.0.4 Released! (fwd)]

8. Ruby Impressions (fwd) (fwd)

9. utility to display the contents of a pickle (fwd) (fwd)

10. get-a-cup-of-coffee slow (fwd) (fwd)

11. Announcing DOS port availability (fwd) (Was: Announcing DOS port availability (fwd))

12. (Fwd) FW: Traveling-Been there, done that

 

 
Powered by phpBB® Forum Software