b.py 1.3 KB

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