Processing and adding numbers from lines.

bearophileHUGS at lycos.com bearophileHUGS at lycos.com
Thu Jan 5 08:31:47 EST 2006


With your input this returns:
[200, 20, 0, 13050]
so it's not what you want, but maybe it can be a starting point for
you:

from re import findall
txt = """\
test test       test description  (100-10-0, 6700 test)
test test       test description  (100-10-0, 6350 test)"""
lines = txt.split("\n")
res = [map(int, findall("[0-9]+", line)) for line in lines]
print map(sum, zip(*res))

Maybe izip and imap can be useful too.
lines can be a file object too.
Bye,
bearophile




More information about the Python-list mailing list