words/is-palindrome.py
Check whether text is a palindrome, ignoring case, spaces, and punctuation. Pure computation, no network.
Use when the user asks whether a word or phrase is a palindrome.
- the file
- words/is-palindrome.py
- its skill
- words/SKILL.md (the whole words pack)
- as knowledge
- okf/words/is-palindrome.md
- on GitHub
- words/is-palindrome.py ↗
Run it
1. Once per machine: install fragletc (Docker must already be running).
curl -fsSL https://raw.githubusercontent.com/ofthemachine/fraglet/main/install.sh | sh
2. Fetch the tool and print its contract.
curl -fsSLO https://tools.ofthemachine.com/words/is-palindrome.py && chmod +x is-palindrome.py && ./is-palindrome.py --fraglet-help
3. Run it.
./is-palindrome.py -p text="<text>"
Parameters
| name | type | requirement | description |
|---|---|---|---|
| text | string | required | Text to check |
Outputs
stdout
Provenance
- image
- ofthemachine/python3@sha256:a015b4f9f0e7c1648f8fcd4164f6a296dd3c9189404f88f333a9764d08d13522
- reach
network=none— a run is a pure function of its inputs; results are safe to memoize.- procedure_hash
- sha256:4eb8633759beea213209997e680d6da3d9511f1e98223c352d525feb26cc632b
- receipt
- add
--receipt run.jsonto any run;receipt/attest.pyverifies it against this hash without re-running.
Source
is-palindrome.py · 14 lines · sha256 4eb8633759be…
#!/usr/bin/env -S fragletc --image ofthemachine/python3@sha256:a015b4f9f0e7c1648f8fcd4164f6a296dd3c9189404f88f333a9764d08d13522
#: d=Check whether text is a palindrome, ignoring case, spaces, and punctuation. Pure computation, no network.
#: when=Use when the user asks whether a word or phrase is a palindrome.
#: network=none
#: stdin=none
#: param=text:required:d=Text to check
import os
import re
text = os.environ["TEXT"]
cleaned = re.sub(r"[^a-z0-9]", "", text.lower())
is_pal = len(cleaned) > 0 and cleaned == cleaned[::-1]
print(f"Palindrome: {'yes' if is_pal else 'no'}")
print(f"Cleaned: {cleaned}")