Skip to content

Instantly share code, notes, and snippets.

@def-
Created November 27, 2018 17:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save def-/192e7bbdff4e68f599605d20603ece9f to your computer and use it in GitHub Desktop.
Save def-/192e7bbdff4e68f599605d20603ece9f to your computer and use it in GitHub Desktop.
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