memsort.py 455 B

123456789101112131415161718192021222324252627282930313233343536
  1. import sys
  2. arg = "memdump.txt"
  3. if (len(sys.argv) > 1):
  4. arg = sys.argv[1]
  5. f = open(arg, "rb")
  6. l = f.readline()
  7. sum = {}
  8. cnt = {}
  9. while(l != ""):
  10. s = l.split("-")
  11. amount = int(s[1])
  12. what = s[2]
  13. if (what in sum):
  14. sum[what] += amount
  15. cnt[what] += 1
  16. else:
  17. sum[what] = amount
  18. cnt[what] = 1
  19. l = f.readline()
  20. for x in sum:
  21. print(x.strip() + "(" + str(cnt[x]) + "):\n: " + str(sum[x]))