`
dqifa
  • 浏览: 112246 次
社区版块
存档分类
最新评论
文章列表
python 求最长非连续公共子串算法LCS 动态规划求最长非连续公共子串算法LCS参照算法网址:http://blog.chinaunix.net/u1/35100/showart_415862.html入口: 两个 要比较的串 S1,S2返回 : 最长非连续公共子串 S #coding=gbk # class TEMT: L,IX1,IX2 =0,0,0 def WLCS( s1,s2 ): n1 = len( s1 ) n2 = len( s2 ) if n1==0 or n2==0: return "& ...
LCS (Longest Common Subsequence) 算法用于找出两个字符串最长公共子串。算法原理:(1) 将两个字符串分别以行和列组成矩阵。(2) 计算每个节点行列字符是否相同,如相同则为 1。(3) 通过找出值为 1 的最长对角线即可得到最长公共子串。  人 民 共 和 时 代中 0, 0, 0, 0, 0, 0华 0, 0, 0, 0, 0, 0人 1, 0, 0, 0, 0, 0民 0, 1, 0, 0, 0, 0共 0, 0, 1, 0, 0, 0和 0, 0, 0, 1, 0, 0国 0, 0, 0, 0, 0, 0为进一步提升该算法,我们可以将字符相同节点(1)的值加上 ...
#!/user/bin/env python # -*- coding: utf-8 -*- class arithmetic(): def __init__(self): pass ''' 【编辑距离算法】 【levenshtein distance】 【字符串相似度算法】 ''' def levenshtein(self,first,second): if len(first) > len(second): first,seco ...
python:目录与文件操作os和os.path模块os.listdir(dirname):列出dirname下的目录和文件os.getcwd():获得当前工作目录os.curdir:返回但前目录('.')os.chdir(dirname):改变工作目录到dirnameos.path.isdir(name):判断name是不是一个目录,name不是目录就返回falseos.path.isfile(name):判断name是不是一个文件,不存在name也返回falseos.path.exists(name):判断是否存在文件或目录nameos.path.getsize(name):获得文件大小,如 ...
#encoding=utf-8 # 甄码农代码 2012 03 06 # 打开sqlite3内存数据库,执行操作,将内存数据库保存到文件 import sqlite3 import StringIO #使用:memory:标识打开的是内存数据库 con = sqlite3.connect(":memory:") cur = con.cursor() #使用executescript可以执行多个脚本 cur.executescript(""" create table quotes( rid I ...
这是我写的一个使用 pysqlite2 写的数据库备份的小程序,功能相对简单。它可以将指定的库备份成Insert语句。代码如下: #coding=cp936 #本程序用于sqlite数据库的备份,备份结果为SQL的INSERT语句 #本程序适用于pysqlite2版本 #开发者:limodou #版权:GPL # import sqlite3 as sqlite import os.path def dbbackup(dbname, path='', singlefile=False, encoding='utf-8'): """备份 ...
A common question is how to dynamically update the list in a GridCellChoiceEditor. The problem comes from not having direct access to the underlying ComboBox widget in the grid editor. Fortunately the grid editor throws an event that allows us to get to the underlying ComboBox. In addition to dynam ...
  # -*- coding: cp936 -*- import wx import wx.grid import wx.lib.gridmovers as gridmovers import pymssql connect=pymssql.connect(host='wxpython',user='sa',password='',database='THIS4_0807') cursor=connect.cursor() ascordesc=True class LineupTable(wx.grid.PyGridTableBase): def __in ...
今天开发了一个wraptext模块,它可以对文本进行折行处理。详情:  说明    本程序用来进行文本的折行处理,支持中文和英文,可以处理Unicode和普通字符串  参数说明    text       待处理的文本,可以是unicode或str    wi ...
先来看个例子: def foo(*args, **kwargs):       print 'args = ', args       print 'kwargs = ', kwargs       print '---------------------------------------'      if __name__ == '__main__':       foo(1,2,
编写环境: 1、ActivePython-2.7.2.5-win32-x86 2、wxPython2.8-win32-unicode-2.8.12.1-py27 3、wxFormBuilder_v3.3.3-beta   以下代码是演示如何在wxGrid中增加wxDataPickerCtrl控件的代码,是我查了好久才找到的。 import wx import wx.grid class DatePickerCellEditor(wx.grid.PyGridCellEditor): def __init__(self): wx.grid.Py ...
编写环境: 1、ActivePython-2.7.2.5-win32-x86 2、wxPython2.8-win32-unicode-2.8.12.1-py27 3、wxFormBuilder_v3.3.3-beta   以下代码是演示怎样利用IEHtmlWindow载入网页,并实现打印预览和打印的的功能: #coding:utf-8 import wx from wx.lib import iewin class MyFrame ( wx.Frame ): def __init__( self, parent ): ...
Global site tag (gtag.js) - Google Analytics