Skip to content

Instantly share code, notes, and snippets.

@KKarthikeya
Created August 16, 2015 04:25
Show Gist options
  • Save KKarthikeya/472b419dcb8473d6ba3c to your computer and use it in GitHub Desktop.
Save KKarthikeya/472b419dcb8473d6ba3c to your computer and use it in GitHub Desktop.
Write a program that prompts for a file name, then opens that file and reads through the file, looking for lines of the form: X-DSPAM-Confidence: 0.8475 Count these lines and extract the floating point values from each of the lines and compute the average of those values and produce an output as shown below. You can download the sample data at h…
sum = 0.0
count = 0
fname = open(raw_input("Enter file name: "))
for line in fname:
if not line.startswith("X-DSPAM-Confidence:") : continue
sum = sum + float(line[line.find(" ")+1:])
count = count + 1
print "Average spam confidence:",sum/float(count)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment