list comprehension

Guy Robinson guy at NOSPAM.r-e-d.co.nz
Sun May 9 20:32:20 EDT 2004


Hello,

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.

TIA,

Guy



More information about the Python-list mailing list