Skip to content

Instantly share code, notes, and snippets.

@krmgns
Created March 10, 2019 23:11
Show Gist options
  • Save krmgns/3077e615ce02f2bf9bfe9aa5694866cd to your computer and use it in GitHub Desktop.
Save krmgns/3077e615ce02f2bf9bfe9aa5694866cd to your computer and use it in GitHub Desktop.
def fn_vector(words):
import re, locale
#global words
def slug(words):
return fn_slug(words)
i = 0
dic = {}
words = slug(words)
for word in re.split('\s+', words):
i = i + 1; # position
c = [i];
if (word in dic):
c = dic[word]
c.append(i)
dic[word] = c
arr = []
for word, c in dic.items():
c = ','.join(map(str, c))
arr.append('%s:%s' % (word, c))
locale.setlocale(locale.LC_COLLATE, 'tr_TR.UTF-8')
arr.sort(key=locale.strxfrm)
return ' '.join(arr)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment