{"record":{"id":"0dcb0616cb7890ef","repo":"TheAlgorithms/Python","slug":"duplicate-symbol-i","errorCode":null,"errorMessage":"Duplicate symbol ({i})","messagePattern":"Duplicate symbol \\((.+?)\\)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"ciphers/enigma_machine2.py","lineNumber":153,"sourceCode":"        msg = f\"Plugboard setting isn't type string ({type(pbstring)})\"\n        raise TypeError(msg)\n    elif len(pbstring) % 2 != 0:\n        msg = f\"Odd number of symbols ({len(pbstring)})\"\n        raise Exception(msg)\n    elif pbstring == \"\":\n        return {}\n\n    pbstring.replace(\" \", \"\")\n\n    # Checks if all characters are unique\n    tmppbl = set()\n    for i in pbstring:\n        if i not in abc:\n            msg = f\"'{i}' not in list of symbols\"\n            raise Exception(msg)\n        elif i in tmppbl:\n            msg = f\"Duplicate symbol ({i})\"\n            raise Exception(msg)\n        else:\n            tmppbl.add(i)\n    del tmppbl\n\n    # Created the dictionary\n    pb = {}\n    for j in range(0, len(pbstring) - 1, 2):\n        pb[pbstring[j]] = pbstring[j + 1]\n        pb[pbstring[j + 1]] = pbstring[j]\n\n    return pb\n\n\ndef enigma(\n    text: str,\n    rotor_position: RotorPositionT,\n    rotor_selection: RotorSelectionT = (rotor1, rotor2, rotor3),\n    plugb: str = \"\",","sourceCodeStart":135,"sourceCodeEnd":171,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/ciphers/enigma_machine2.py#L135-L171","documentation":"Raised by _plugboard() when the same letter appears more than once in the plugboard string. Each letter can be connected to at most one partner, so duplicates like 'PICTURES' containing two S's (or 'AABB'-style repeats) are rejected.","triggerScenarios":"_plugboard('PICTURES') — S occurs twice; any string where a letter is used in two different pairs; self-pairs like 'PP'.","commonSituations":"Hand-composed settings that accidentally reuse a letter; concatenating pair lists that share a letter; converting a dict where two keys map to the same value.","solutions":["Ensure every letter appears exactly once: use distinct pairs like 'POLA' or 'AMFILEV'","Validate uniqueness first: len(set(pb)) == len(pb)","Build settings programmatically from a disjoint-pairs structure"],"exampleFix":"# before\npb = 'PICTURES'  # S used twice\n\n# after\npb = 'PICTURED'  # all letters distinct (example)","handlingStrategy":"validation","validationCode":"assert len(set(pb)) == len(pb), 'each plugboard letter may appear once'","typeGuard":"def has_unique_symbols(pb: str) -> bool:\n    pb = pb.replace(' ', '')\n    return len(set(pb)) == len(pb)","tryCatchPattern":"try:\n    pbdict = _plugboard(pb)\nexcept Exception as exc:\n    if \"Duplicate symbol\" in str(exc):\n        raise ConfigError(f'plugboard letter reused: {exc}') from exc\n    raise","preventionTips":["Check len(set(pb)) == len(pb) before calling","Model plugboard as a set of disjoint pairs in your code, then serialize","Reject self-pairs ('PP') — they also count as duplicates"],"tags":["enigma","plugboard","duplicate","validation"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}