list comprehension

Aahz aahz at pythoncraft.com
Sun May 9 23:18:48 EDT 2004


In article <c7ml6k$c88$1 at lust.ihug.co.nz>,
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

Performance I can understand (which Shalabh addressed quite nicely), but
why do you care about compressing the source code?  This is simple,
straightforward, and easy to read; surely that's more important than
saving a few bytes?
-- 
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

Adopt A Process -- stop killing all your children!



More information about the Python-list mailing list