Last active
September 3, 2022 14:34
-
-
Save amol9/26b7982e1f10427cafd22c68f36f0bef to your computer and use it in GitHub Desktop.
Python script to subscript numbers in chemical formulae
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
p = "Hello world3 33" | |
import re | |
pfx = r"([a-zA-Z\)])" | |
p = re.sub(pfx + "0", r"\1₀", p) | |
p = re.sub(pfx + "1", r"\1₁", p) | |
p = re.sub(pfx + "2", r"\1₂", p) | |
p = re.sub(pfx + "3", r"\1₃", p) | |
p = re.sub(pfx + "4", r"\1₄", p) | |
p = re.sub(pfx + "5", r"\1₅", p) | |
p = re.sub(pfx + "6", r"\1₆", p) | |
p = re.sub(pfx + "7", r"\1₇", p) | |
p = re.sub(pfx + "8", r"\1₈", p) | |
p = re.sub(pfx + "9", r"\1₉", p) | |
print (p) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment