数据结构
smallTutou
这个作者很懒,什么都没留下…
展开
-
排序算法桶排序
排序算法,桶排序原创 2022-06-10 18:12:20 · 137 阅读 · 1 评论 -
斐波那契数列
斐波那契数列 ##递归方式 """斐波那契函数:1,1,2,3,5,8..""" def fib(index): if index <= 2: return 1 else: return fib(index-1)+fib(index-2) ##普通方式 def fib(index): re_list = [] n,a,b = 0,0,1 while n < index: re_list.append(b)原创 2022-04-08 16:04:54 · 89 阅读 · 0 评论 -
利用tf-idf提取关键词
##读取.txt并保存为.txt from jieba import analyse f = open("result.txt", "w", encoding="utf-8") for line in open("text.txt",encoding="utf-8"): tfidf = analyse.extract_tags text = line keywords = tfidf(text, topK=4, withWeight=False, allowPOS=())原创 2022-04-08 15:27:13 · 1693 阅读 · 0 评论 -
单词拼写纠错
from nltk.corpus import reuters from docx import Document from nltk import sent_tokenize, word_tokenize import re import numpy as np #词典库 vocab = [] for line in open("data/spell-testset1.txt"): items = line.split(":") item = items[0].strip() v原创 2022-04-08 15:20:18 · 100 阅读 · 0 评论 -
词性标注pos_tagging
import numpy as np #1.构造词典、词性库 tag2id,id2tag = {},{} word2id ,id2word = {},{} for line in open("traindata.txt"): items = line.split("/") tag,word = items[1].rstrip(),items[0] if tag not in tag2id: tag2id[tag] = len(tag2id) i原创 2022-04-08 15:14:36 · 286 阅读 · 0 评论 -
二叉树创建
#定义树节点 class Node(object): def __init__(self,data): #data为树节点存储数据,left左子树,right右子树 self.elem = data self.lchild = None self.rchild = None #创建二叉树 class BinTree(object): def __init__(self): self.root = None .原创 2022-04-08 15:09:48 · 95 阅读 · 0 评论