list comprehension

Aahz aahz at pythoncraft.com
Sun May 9 21:01:24 EDT 2004


In article <c7mii9$988$1 at lust.ihug.co.nz>,
Guy Robinson  <guy at NOSPAM.r-e-d.co.nz> wrote:
>
>Trying to change a string(x,y values) such as :
>
>s = "114320,69808 114272,69920 113568,71600 113328,72272"
>
>into (x,-y):
>
>out = "114320,-69808 114272,-69920 113568,-71600 113328,-72272"
>
>I tried this:
>
>print [(a[0],-a[1] for a in x.split(',')) for x in e]
>
>But it doesn't work. Can anyone suggest why or suggest an alternative 
>way? The text strings are significantly bigger than this so performance 
>is important.

When in doubt, break a problem into smaller steps.  Let me play Socrates
for a minute: what's the first step in working with your dataset?
-- 
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