list comprehension

Tim Roberts timr at probo.com
Mon May 10 00:52:53 EDT 2004


Guy Robinson <guy at NOSPAM.r-e-d.co.nz> wrote:

>This works I was just wondering if something could be written more 
>concisely and hopefully faster:
>
>s = "114320,69808 114272,69920 113568,71600 113328,72272"
>e = s.split(' ')
>out =''
>for d in e:
>     d =d.split(',')
>     out +='%s,%d ' %(d[0],-int(d[1]))
>print out

Well, why not the more obvious:  s.replace(',',',-')
-- 
- Tim Roberts, timr at probo.com
  Providenza & Boekelheide, Inc.



More information about the Python-list mailing list