Skip to content

Instantly share code, notes, and snippets.

@k-gun

k-gun/fn_slug.py

Created Mar 10, 2019
Embed
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)
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
You can’t perform that action at this time.