This Python script attempts to match a user-provided word to a sequence of chemical element symbols (like He, Li, O, etc.), even if the match is imperfect. It uses a recursive backtracking algorithm with a configurable tolerance for spelling mismatches.
Given an input word (e.g. hello), the script will:
- Convert it to lowercase.
- Search for substrings that match element symbols (like
h,he,li, etc.). - Allow a specified number of character mismatches (
max_mismatches). - Return the best possible combination of element symbols that reconstructs the word, partially or fully.
Enter a word: unicorn
Output: Closest match found (2 letters off): UCoRn Elements: U (Uranium), Co (Cobalt), Rn (Radon) Unmatched letters: ni
You can change the allowed number of character mismatches in the fuzzy_spell() function by modifying the max_mismatches parameter:
result = fuzzy_spell(word, max_mismatches=2)Complete list of 118 periodic table elements Case-insensitive matching Supports fuzzy spelling with customizable mismatch tolerance Highlights unmatched characters
Python 3.x
git clone github.com/Chaose3/Periodic_Table.gitcd Periodic Tablepython fuzzy_elements.pyEnter a word and see if it can be constructed from element symbols!
Educational chemistry games
Science-themed puzzles
Chemistry name generators
Nerdy Easter eggs ๐ง
This project is open-source and free to use under the MIT License.