Created
August 26, 2013 01:36
-
-
Save blech/6337420 to your computer and use it in GitHub Desktop.
Make Unicode sub- and super-scripts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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