DEV Community

loading...

Discussion on: Daily Challenge #259 - Duplicate Encoder

Collapse
rafaacioly profile image
Rafael Acioly

Python solution 🐍

from collections import Counter

ONCE, MANY = '(', ')'


def parse(text: str) -> str:
  normalized_text = text.lower()
  letter_counter = Counter(normalized_text)

  result: str = normalized_text
  for letter in normalized_text:
    result = result.replace(
      letter,
      MANY if letter_counter.get(letter) > 1 else ONCE
    )

  return result