Skip to content

Instantly share code, notes, and snippets.

@nvictor
Last active August 11, 2024 23:00
Show Gist options
  • Save nvictor/d6e9f2390636f3a34158270faf419284 to your computer and use it in GitHub Desktop.
Save nvictor/d6e9f2390636f3a34158270faf419284 to your computer and use it in GitHub Desktop.
p.py
# NOTE(victor): Python for Code Golf.
import runpy
import sys
import importlib
builtins = sys.modules['builtins']
builtins.only = filter
builtins.seq = range
builtins.out = print
builtins.use = importlib.import_module
builtins.index = lambda s,m,n: next((i for i,x in enumerate(s) if x==m),n)
builtins.rindex = lambda s,m,n: next((i for i,x in reversed(list(enumerate(s))) if x==m),n)
if len(sys.argv) < 2:
print("Usage: python -m p <script_name>")
sys.exit(1)
runpy.run_path(sys.argv[1])
# 20240802_5.py
# out(*only(use("calendar").isleap,seq(1800,2401)))
# 20240908.py
# s=[0]
# for i in seq(1000):s+=[i-rindex(s[:-1],s[i],i)]
# out(*s,sep=", ")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment