f = open("scores.txt").read().split('\n\n') from sys import argv thresh = 1 if len(argv) > 1: thresh = int(argv[1]) entries = [] for entry in f: if not entry: continue items = entry.split() score = int(items[0]) entries.append((score, entry)) entries.sort() entries.reverse() f = open("scores.txt", "w") for entry in entries: if entry[0] < thresh: continue f.write((entry[1]+'\n\n').replace('\n ', '\n\t'))