a.py 1022 B

12345678910111213141516171819202122232425262728293031323334353637
  1. import os, argparse
  2. def solve_task(filename):
  3. with open(filename) as infile:
  4. total = 0
  5. thisGroup = {}
  6. for raw_line in infile:
  7. line = raw_line.rstrip()
  8. if line == "":
  9. #print(len(thisGroup))
  10. total += len(thisGroup)
  11. thisGroup = {}
  12. continue
  13. for c in line:
  14. if c in thisGroup:
  15. thisGroup[c] += 1
  16. else:
  17. thisGroup[c] = 1
  18. #print(len(thisGroup))
  19. total += len(thisGroup)
  20. print(f"Total: {total}")
  21. os.system("pause")
  22. def parse_arguments():
  23. parser = argparse.ArgumentParser(description="Script that solves the case",epilog="Have a nice day!")
  24. parser.add_argument('filename', nargs='?', default="example.txt", help='Input file')
  25. args = parser.parse_args()
  26. return args
  27. def main():
  28. args = parse_arguments()
  29. solve_task(args.filename)
  30. if __name__ == "__main__":
  31. main()