f = open("Input_test_scores.txt", 'r') f2 = open("best_scores.txt", 'w') l =  for line in f: s = line.split() name = s score = s l1 = [name, score] #print name l.append(l1) def mycmp(x,y): if x < y: print "less\n" return -1 elif x>y: print "more\n" return 1 else: return 0 l.sort(mycmp) for i in l: #print i f2.write(i and i) f.close() f2.close()
And example of the grades would be like this:
bob 23$ jill 78$ bill 100$ george 99$ mary 98$ tim 45$
And the output file should show like this:
bill 100 george 99 mary 98
The $ shows the end of the line, I want it removed in the final result but I think I can figure the strip command out if I can get the rest... Anyone able to help me? Please?!?!?!
** A quick edit **
I know about the print more/less lines not needing to be there, those were my attempt to see if the sort was running, and it seems to only be partially running.
This post has been edited by gryphin: 20 January 2010 - 01:10 PM