Skip to content

Instantly share code, notes, and snippets.

@donlovett
Created September 16, 2016 20:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save donlovett/ec395cf4c2c54f443cfff0a6044da9ca to your computer and use it in GitHub Desktop.
Save donlovett/ec395cf4c2c54f443cfff0a6044da9ca to your computer and use it in GitHub Desktop.
Week 2 Coursera Web python
# Search for lines that start with From and have an at sign
import re
#fname = raw_input('Enter file:')
#hand = open(fname)
hand = open("/home/vagrant/Coursera/Week2/regex_sum_318168.txt")
nums = list()
z = 0
for line in hand:
line = line.rstrip()
x = re.findall('([0-9]+)', line)
y = len(x)
#if len(x) > 0 :
if y > 0 :
for z in range (0 , y):
val = int(x[z])
#val = int(x[:len(nums)])
nums.append(val)
#print (nums)
print len(nums)
print sum(nums)
for item in nums[:len(nums)]:
print item
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment