Created
September 16, 2016 20:25
-
-
Save donlovett/ec395cf4c2c54f443cfff0a6044da9ca to your computer and use it in GitHub Desktop.
Week 2 Coursera Web python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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