tools / words / is-palindrome.py

words/is-palindrome.py

wordscomputation○ hermeticpython3

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.

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

nametyperequirementdescription
textstringrequiredText 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.json to any run; receipt/attest.py verifies 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}")