Python: search numbers in a file and sum them

## python assigment from Using Python to Access Web Data, sum numbers in file
import re
file = open('regex_sum_215939.txt')
 num = list()
 for line in file:
aux = re.findall('[0-9]+', line)
  num.extend(aux)
print (sum(int(i) for i in num))
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s