473,385 Members | 1,351 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Processing and adding numbers from lines.

Hello, Group:

Is there an easy way to automate the processing of adding the following
numbers in two lines?

test test test description (100-10-0, 6700 test)
test test test description (100-10-0, 6350 test)

I'd like to be able run a script on the file above to produce the
following results.

200-20 .9090

The lines will stay the same, but the numbers will change.

--SF

Jan 5 '06 #1
1 1277
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

Jan 5 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: sp0 | last post by:
Is there a reason why to make mix numbers improper when adding? It seems when subtracting and adding, adding a subtracting the whole numbers and fraction parts should be sufficient? what'ch think
23
by: Daniel Rudy | last post by:
Hello, I'm trying to learn how command line arguments are handled in C. The following code segment that I wrote as a test program compiles, but when I try to run it, it core dumps. This is...
6
by: James Radke | last post by:
Hello, I have a multithreaded windows NT service application (vb.net 2003) that I am working on (my first one), which reads a message queue and creates multiple threads to perform the processing...
6
by: Hareth | last post by:
Scenerio: label1.text = 0 textbox1.text = 0 textbox2.text = textbox1.text + label1.text It turns out it isnt adding the numbers, it attaches the new number next to the old number
3
by: tai.cabrera | last post by:
What I would like to do is input a range of serial numbers in a form and have that range populate in the table without me having to put them in one at a time manually. The numbers do not exist yet,...
6
by: sanfranc415 | last post by:
Hello, Group: Is there an easy way to automate the processing of adding the following numbers in two lines? test test test description (100-10-0, 6700 test) test test test...
17
by: Sri | last post by:
How do you add an n-bit number in C? Regards, Sri
9
suzee_q00
by: suzee_q00 | last post by:
I will admit that lots of times the obvious eludes me and this is most likely one of those times but if anyone has any ideas on what I can do to make this code work, I would greatly appreciate it....
16
by: malibuster | last post by:
I have a text source file of about 20.000 lines. that file, grab the next 5 lines write these to a new file... grabbing 5 lines and creating new files until processing of all 20.000 lines is done....
60
by: Bill Cunningham | last post by:
I have a row of values like such, placed in a text file by fprintf. 10.50 10.25 10.00 10.75 11.00 What I want to do to the above colum is add a new column right beside it which is a total...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.