Created
October 12, 2015 09:48
-
-
Save micolous/ef69a1f4a6ab08434fe1 to your computer and use it in GitHub Desktop.
This file contains 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
from abbreviations import abbreviations | |
from sys import argv | |
import re | |
# get all the commandline text | |
in_str = ' '.join(argv[1:]).upper() | |
# compile a regular expression for each of the stations, do this only on startup, because it is slow (~240 ms) | |
abb_re = {} | |
for k, v in abbreviations.iteritems(): | |
abb_re[re.compile(r'[^A-Z0-9]' + k + r'[^A-Z0-9]')] = v | |
# Do the actual replacement, this is fairly fast (~10ms) | |
for k, v in abb_re.iteritems(): | |
in_str = k.sub(v, in_str) | |
print in_str |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment