TheAlgorithms/Python · error · Exception
'{i}' not in list of symbols
Error message
'{i}' not in list of symbols What it means
Raised by _plugboard() when a symbol in the plugboard string is not in the Enigma alphabet (uppercase A-Z). Lowercase letters, digits, punctuation, or spaces all fail because abc contains only the 26 uppercase letters.
Source
Thrown at ciphers/enigma_machine2.py:150
# a) is type string
# b) has even length (so pairs can be made)
if not isinstance(pbstring, str):
msg = f"Plugboard setting isn't type string ({type(pbstring)})"
raise TypeError(msg)
elif len(pbstring) % 2 != 0:
msg = f"Odd number of symbols ({len(pbstring)})"
raise Exception(msg)
elif pbstring == "":
return {}
pbstring.replace(" ", "")
# Checks if all characters are unique
tmppbl = set()
for i in pbstring:
if i not in abc:
msg = f"'{i}' not in list of symbols"
raise Exception(msg)
elif i in tmppbl:
msg = f"Duplicate symbol ({i})"
raise Exception(msg)
else:
tmppbl.add(i)
del tmppbl
# Created the dictionary
pb = {}
for j in range(0, len(pbstring) - 1, 2):
pb[pbstring[j]] = pbstring[j + 1]
pb[pbstring[j + 1]] = pbstring[j]
return pb
def enigma(
text: str,View on GitHub (pinned to f5988cc097)
Solutions
- Uppercase and strip spaces before calling: _plugboard(pb.upper().replace(' ', ''))
- Use only A-Z symbols in pairs
- Pre-validate every char with all(c in string.ascii_uppercase for c in pb)
Example fix
# before
_plugboard('pictures') # lowercase fails
# after
_plugboard('PICTURES') Defensive patterns
Strategy: validation
Validate before calling
import string
pb = pb.upper().replace(' ', '')
assert all(c in string.ascii_uppercase for c in pb) Type guard
def is_uppercase_alpha(pb: str) -> bool:
return all(c.isalpha() and c.isupper() for c in pb.replace(' ', '')) Try / catch
try:
pbdict = _plugboard(pb)
except Exception as exc:
if "not in list of symbols" in str(exc):
pbdict = _plugboard(pb.upper().replace(' ', ''))
else:
raise Prevention
- Uppercase and strip spaces before calling _plugboard
- Restrict plugboard input to A-Z
- Validate against string.ascii_uppercase in your input form
When it happens
Trigger: _plugboard('pictures') in lowercase; 'PICTUR3S' with a digit; a space inside pairs like 'PI CT' — spaces are not actually stripped and are not in abc.
Common situations: Accepting user input without uppercasing; copy-pasted settings with whitespace; settings from another alphabet convention.
Related errors
- Plugboard setting isn't type string ({type(pbstring)})
- Odd number of symbols ({len(pbstring)})
- Duplicate symbol ({i})
- Please use 3 unique rotors (not {unique_rotsel})
- First rotor position is not within range of 1..26 ({rotorpos
AI-assisted analysis of TheAlgorithms/Python@f5988cc097 (2026-08-14).
Data as JSON: /api/errors/1d26d056b7745746.
Report an issue: GitHub.