tags:

views:

156

answers:

2

Here is the code I'm working with

def ascii_sum():
    x = 0
    infile = open("30075165.txt","r")
    for line in infile:
     return sum([ord(x) for x in line])
    infile.close()

This code only prints out the first ASCII value in the file not the max ASCII value

+1  A: 
max(open(fname), key=lambda line: sum(ord(i) for i in line))
SilentGhost
+1 and if he wants the line number he can do: max(enumerate(open(fname)), key=lambda (i, line): sum(ord(i) for i in line))
Nadia Alramli
+1  A: 

This is a snippet from an answer to one to of your previous questions

def get_file_data(filename):
    def ascii_sum(line):
        return sum([ord(x) for x in line])
    def word_count(line):
        return len(line.split(None))

    filedata = [{'line': line, 
                 'line_len': len(line), 
                 'ascii_sum': ascii_sum(line), 
                 'word_count': word_count(line)}
                for line in open(filename, 'r')]

    return filedata

afile = r"C:\Tmp\TestFile.txt"
file_data = get_file_data(afile)

print max(file_data, key=lambda line: line['line_len']) # Longest Line
print max(file_data, key=lambda line: line['ascii_sum']) # Largest ASCII sum
print max(file_data, key=lambda line: line['word_count']) # Most Words
kjfletch