Skip to content

Instantly share code, notes, and snippets.

@krmgns
Created March 10, 2019 23:11
Show Gist options
  • Save krmgns/0b5e2068b0ba5c2b495de3196eb6f742 to your computer and use it in GitHub Desktop.
Save krmgns/0b5e2068b0ba5c2b495de3196eb6f742 to your computer and use it in GitHub Desktop.
def fn_slug(words):
import re
#global words
chrs = {'ı':'i', 'ö':'o', 'ü':'u', 'ç':'c', 'ğ':'g', 'ş':'s',
'İ':'I', 'Ö':'O', 'Ü':'U', 'Ç':'C', 'Ğ':'G', 'Ş':'S'}
def lower(word):
return word.replace('İ', 'i').replace('I', 'ı').lower()
def replace(word, chrs, ret=None):
for cs, cr in chrs.items():
if cs in word:
ret = word = word.replace(cs, cr)
return ret
ret = []
for word in re.split('([\d]\+[\d])|[^\w]+', words):
if not word: continue
word = re.sub('^[^\w]+|[^\w]+$', '', word)
if len(word) >= 2:
word = lower(word)
ret.append(word)
rep = replace(word, chrs)
if rep:
ret.append(lower(rep))
return ' '.join(ret)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment