8000 GitHub - wjshan/rust-py-tools
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

wjshan/rust-py-tools

Repository files navigation

Python tools compiled by rust

pip install tust-py-tools-d

string

def edit_distance(word1:str,word2:str)->int

计算 word1word2的编辑距离

$m=word1.length, n=word2.length$

时间复杂度: $O(m*n)$

空间复杂度: $O(m*n)$

def string_similarity(word1:str,word2:str)->float:

计算字符串相似度 $1-range/max(word1.length,word2.length)$

$m=word1.length, n=word2.length$

时间复杂度: $O(m*n)$

空间复杂度: $O(m*n)$

class MetchResult

Attributes:

  • first(str): 字符1
  • second(str): 字符2
  • ratio:float: 相似度

def fuzzy_match(first_workds:List[str],second_words:List[str],cutoff:float)->List[MetchResult]:

批量匹配两个列表的内字符的相似度

此方法会将将两个数组做一次笛卡尔乘积运算

时间复杂度: m=first_workds.length,n=second_words.length .$O(mn(a+b))$.a,b为列表包含字符串的平均长度

空间复杂度: $O(m*n)$

def num_distinct(source:str,target:str)->int:

计算在source序列中,子序列target出现的次数

时间复杂度: $O(m*n)$ msource的长度,ntarget的长度

空间复杂度: $O(m)$ 我们需要两个长度为m的数组来记录状态值

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published
0