Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Exercise 11.1
- #import re
- #fhand = open('mbox.txt')
- #count = 0
- #expression = raw_input('Enter a regular expression: ')
- #for line in fhand:
- # line = line.rstrip()
- # if re.search(expression, line) :
- # count = count + 1
- #count = str(count)
- #print 'mbox.txt had ' + count + ' lines that matched ' + expression
- #Exercise 11.2
- import re
- file = raw_input('Enter file: ')
- fhand = open (file)
- x = 0
- y = 0
- total = 0
- count = 0
- for line in fhand:
- line = line.rstrip()
- x = re.findall('New Revision: ([0-9]+)', line)
- if len (x) > 0:
- count = count + 1
- for y in x:
- y = float(y)
- total = total + y
- average = total/count
- print average
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement