department.py 978 B

1234567891011121314151617181920212223242526272829303132333435
  1. """
  2. Calculate percentage level of index for regions
  3. inside the Verenigde Nederlanden.
  4. """
  5. import re
  6. PLAYERS = {}
  7. def calculate_buildings():
  8. """Count working in departments"""
  9. with open('department.txt', 'r') as file:
  10. for line in file:
  11. line = re.sub(r'\s\d\d.*', '', line)
  12. line = re.sub(r'\[.*\]', '', line)
  13. line = line.strip()
  14. try:
  15. count = re.search(r'\+\d+', line).group(0)
  16. count = count.replace('+', '')
  17. player = re.sub(r'\s\(.*', '', line)
  18. if player in PLAYERS:
  19. PLAYERS[player] += int(count)
  20. else:
  21. PLAYERS[player] = 1
  22. except Exception as exception:
  23. print('%s %s' % (line, exception))
  24. for player in sorted(PLAYERS, key=PLAYERS.get, reverse=True):
  25. print('%3s %s' % (PLAYERS[player], player))
  26. if __name__ == '__main__':
  27. calculate_buildings()