Skip to content

Instantly share code, notes, and snippets.

@cpinto
Created March 11, 2009 23:24
Show Gist options
  • Save cpinto/77812 to your computer and use it in GitHub Desktop.
Save cpinto/77812 to your computer and use it in GitHub Desktop.
Single line url shortener in python
# usage: gen_token(n)
# Pass this the numerical ID of an URL at the cross reference table
# and you'll get a tinyurl-like base36 string
gen_token=lambda n,cs="0123456789abcdefghijklmnopqrstuvwxyz":(lambda b=len(cs):cs[n%b]+gen_token((n-(n%b))/b))() if n else ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment