DEV Community

Discussion on: Daily Challenge #272 - Printer Errors

Collapse
 
rafaacioly profile image
Rafael Acioly

Python solution 🐍

from collections import Counter

def print_errors(colors: str) -> str:
  color_tracker = Counter(colors)
  allowed_colors = range(ord('a'), ord('n'))  # same as "ord('m') + 1"
  color_errors = 0
  for color, amount in color_tracker.items():
    if ord(color) not in allowed_colors:
      color_errors += amount

  return f"{color_errors}/{len(colors)}"