Skip to content

Instantly share code, notes, and snippets.

@blech
Created August 26, 2013 01:36
Show Gist options
  • Save blech/6337420 to your computer and use it in GitHub Desktop.
Save blech/6337420 to your computer and use it in GitHub Desktop.
Make Unicode sub- and super-scripts
#!/usr/bin/python
# -*- coding: utf8 -*-
def up(input):
normal = u"0123456789+-()"
superscript = u"⁰¹²³⁴⁵⁶⁷⁸⁹⁺⁻⁽⁾"
trantab = dict((ord(a), ord(b)) for a, b in zip(normal, superscript))
return input.translate(trantab)
def down(input):
normal = u"0123456789+-()"
subscript = u"₀₁₂₃₄₅₆₇₈₉₊₋₍₎"
trantab = dict((ord(a), b) for a, b in zip(normal, subscript))
return input.translate(trantab)
if __name__ == "__main__":
test = u"9876+5432-(10)"
print up(test).encode('utf-8')
print down(test).encode('utf-8')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment