- 博客(11)
- 收藏
- 关注
原创 k值近邻法python3实现
代码:from numpy import *import operatordef createDataSet():group=array([[1.0,1.1],[1.0,1.0],[0,0],[0,0.1]])labels=['A','A','B','B']return group,labelsdef classify0(inX,dataSet,labels,k
2017-12-13 14:26:43 282
原创 python生成随机测试文件
import random# The quiz data. Keys are states and values are their capitals.capitals = {'Alabama': 'Montgomery', 'Alaska': 'Juneau', 'Arizona': 'Phoenix','Arkansas': 'Little Rock', 'California': 'S
2017-12-06 17:03:58 492
原创 python实现强口令检测
import repassword=str(input())def detection(password): if len(password)8: return False m=re.compile(r'\d+') if m.search(password)==None: return False n=re.compile(r
2017-12-04 18:37:11 2255
原创 python正则表达式提取文本中的电话号码和邮箱
代码:#! python3import pyperclip,rephoneregex = re.compile(r'''(\d{3}|\(\d{3}\))? # area code(\s|-|\.)? # separator(\d{3}) # first 3
2017-12-04 16:54:10 10745
原创 sieve 筛选法
def _odd_iter(): n = 1 while True: n = n + 2 yield n #2把偶数都筛选了def _not_divisible(n): return lambda x: x % n > 0def primes(): yield 2 it = _odd_iter() # 初始序列
2017-11-24 15:25:49 649
原创 另外1种求最大公约数的算法
def gcd(m,n): t=min(m,n) while m%t!=0 or n%t!=0: t=t-1 return tprint(gcd(60,24))run:12
2017-11-24 11:04:55 152
原创 euclid最大公约数算法
def euclid(m,n): while n!=0: r=m%n m=n n=r else: return mprint(euclid(60,24))运行结果:12
2017-11-24 10:50:22 638
原创 狄克斯特拉算法python
graph={}graph["start"]={}graph["start"]["a"]=2graph["start"]["b"]=6graph["a"]={}graph["a"]["final"]=1graph["b"]={}graph["b"]["a"]=3graph["b"]["final"]=5graph["final"]={}infinity=float('
2017-11-21 18:58:52 437
原创 选择排序Python3实现
def findsmallest(array): smallest=array[0] smallest_index=0 for i in range(1,len(array)): if array[i]<smallest: smallest=array[i] smallest_index=i retur
2017-11-13 20:08:49 242
原创 二分查找算法Python3实现
def binarysearch(list,item): low=0 high=len(list)-1 while low<=high: mid=int((low+high)/2) guess=list[mid] if guess==item: return mid if guess>i
2017-11-13 19:30:41 1738
原创 算法导论学习-插入排序python实现
def insertionsort(A): for j in range(1,len(A)): key=A[j] i=j-1 while i>=0 and A[i]>key: A[i+1]=A[i] i=i-1#compare with the digital in front of i
2017-11-06 17:03:19 189
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人