Skip to content

Instantly share code, notes, and snippets.



Created Mar 10, 2019
What would you like to do?
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)
rep = replace(word, chrs)
if rep:
return ' '.join(ret)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.