In [148]:
from urllib.request import urlopen
url_response = urlopen('http://www.py4inf.com/code/mbox-short.txt')
contents = str(url_response.read())
In [149]:
lines = contents.split('\\n')
In [186]:
total = 0
count = 0
for line in lines:
if line.startswith('X-DSPAM-Confidence'):
(_, value) = line.split(':')
total += float(value)
count = count + 1
print(total/count)
In [184]:
values = [float(line.split(':')[1]) for line in lines if line.startswith('X-DSPAM-Confidence')]
sum(values) / len(values)
Out[184]:
In [ ]: