list comprehension

郁志华 YuZH at spdb.com.cn
Sun May 9 21:07:20 EDT 2004


>>> ' '.join(map(lambda x:x[0]+',-'+x[1],[a.split(',') for a in s.split()]))
'114320,-69808 114272,-69920 113568,-71600 113328,-72272'

-----邮件原件-----
发件人: Guy Robinson [mailto:guy at NOSPAM.r-e-d.co.nz] 
发送时间: 2004年5月10日 8:32
收件人: python-list at python.org
主题: list comprehension


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
-- 
http://mail.python.org/mailman/listinfo/python-list




More information about the Python-list mailing list