-
-
Save def-/192e7bbdff4e68f599605d20603ece9f to your computer and use it in GitHub Desktop.
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
import re | |
import timeit | |
def deslugify2(string): | |
try: | |
n = u'' | |
t = 0 | |
i = 0 | |
for c in string: | |
if t == 0: | |
if c == '-': | |
t = 1 | |
else: | |
n += c | |
else: | |
if c == '-': | |
n += unichr(i) | |
t = 0 | |
i = 0 | |
else: | |
i = i * 10 + int(c) | |
return n.encode('utf-8') | |
except: | |
return string | |
def deslugify3(name): | |
for special_char in re.findall('(-([\d]+)-)', name): | |
name = name.replace(special_char[0], unichr(int(special_char[1]))) | |
return name.encode('utf-8') | |
print timeit.timeit('deslugify2("-60-B-181-mM-62-")', setup="from __main__ import deslugify2") | |
print timeit.timeit('deslugify3("-60-B-181-mM-62-")', setup="from __main__ import deslugify3") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment