diff options
| author | Mac Mollison <mollison@cs.unc.edu> | 2009-02-24 19:58:06 -0500 |
|---|---|---|
| committer | Mac Mollison <mollison@cs.unc.edu> | 2009-02-24 19:58:06 -0500 |
| commit | b58af7d7e4e5a7663dd5a3d3b050a20948628437 (patch) | |
| tree | ec5e7271b4770319a4262cccd835d45363c2ec2a | |
| parent | ace5fe6fd1d7e25f2a213a1f5420142df85f55f4 (diff) | |
Finished sort2 to sort by two keys
| -rwxr-xr-x | sta.py | 11 |
1 files changed, 11 insertions, 0 deletions
| @@ -75,6 +75,17 @@ class Trace: | |||
| 75 | else: | 75 | else: |
| 76 | return 0 | 76 | return 0 |
| 77 | self.iter = sorted(self.iter, key=sortfunc) | 77 | self.iter = sorted(self.iter, key=sortfunc) |
| 78 | |||
| 79 | def sort2(self, key1, key2): | ||
| 80 | """Return the records sorted by two keys""" | ||
| 81 | def sortfunc(record): | ||
| 82 | score = 0 | ||
| 83 | if key1 in record: | ||
| 84 | score += record[key1] | ||
| 85 | if key2 in record: | ||
| 86 | score = float(str(score) + '.' + str(record[key2])) | ||
| 87 | return score | ||
| 88 | self.iter = sorted(self.iter, key=sortfunc) | ||
| 78 | 89 | ||
| 79 | def print_records(self): | 90 | def print_records(self): |
| 80 | """Prints all records in the trace""" | 91 | """Prints all records in the trace""" |
