python判断字符串包含的方法,所有语言中,python的这种判断方法可以说是最直观简单的。#!/usr/bin/env python## [代码名字: String contains string test]# [代码分类: Python Core]# [代码描述: Test if a string contains another str……继续阅读 » 7年前 (2019-07-11) 3025浏览 2716个赞
C语言多种方法求解字符串编辑距离问题编辑距离:通过插入、删除、替换一个字符(和交换相邻字符)的操作,使得字符串A和字符串B相同,而最少的操作次数就是编辑距离。如字符串abcd和aca的距离是2/* 递归搜索 */int calDistance1(char *ptrX, int xbeg, int xend, char *ptrY, int ybeg, i……继续阅读 » 8年前 (2019-07-11) 3132浏览 1567个赞
javascript为数字添加逗号千分符function CommaFormatted(amount) { var delimiter = ","; // replace comma if desired var a = amount.split('.',2) var d = a[1]; var i = pa……继续阅读 » 8年前 (2019-07-11) 3159浏览 2218个赞
php查询mysql数据库prepare语句用法,使用prepare可以优化数据库查询$mysql = new mysqli('localhost', 'root', 'root', 'databaseName') or die('There was a proble……继续阅读 » 8年前 (2019-07-11) 3201浏览 649个赞
调用JavaScript数组元素的多个属性或者方法,应该先把数组元素放到变量里,然后依靠变量调用,不要每次都直接使用数组元素调用//直接使用数组元素调用,慢myArray[myIndex].myMethod1();myArray[myIndex].myMethod2();myArray[myIndex].my_variable;//放到变量里再通过……继续阅读 » 8年前 (2019-07-11) 2075浏览 701个赞
通过SSH在本地控制远程服务器执行命令,如果每次都要登录到远程服务器真的好麻烦,起始通过SSH就可以远程执行在本地使用 ssh $RemoteNode 可以在执行远程机器上的命令,例如 ssh user@node ls /local 会执行远程机器上的 ls /local 命令,如果想在远程机器上连续执行多条命令,可以用单引号或者双引号将这些命令……继续阅读 » 8年前 (2019-06-27) 2090浏览 2538个赞
执行Go代码时可以附加参数,包括要执行的命令和给命令的参数package mainimport ( "os" "os/exec" "fmt" "flag" "strings")func main() { command := f……继续阅读 » 8年前 (2019-05-24) 2895浏览 320个赞
滚动条滚动到页面底部附近时动态加载内容显示var loading = false;$(window).scroll(function(){ if((($(window).scrollTop()+$(window).height())+250)>=$(document).height()){ if(loading == fal……继续阅读 » 8年前 (2019-02-27) 2464浏览 2347个赞
本代码演示了python如何接受命令行参数##Chris Hall 9/13/11def main(argv): sys.path.append('models') #Usage will display when the user asks for help (-h) or when something ……继续阅读 » 8年前 (2018-10-24) 2773浏览 667个赞
Python 获得当前程序所在路径import osprint(os.path.abspath('.'))……继续阅读 » 8年前 (2018-10-24) 4069浏览 1819个赞
py-leveldb 是 Google 的 K/V 数据库 LevelDB 的 Python 客户端开发包。import leveldbdb = leveldb.LevelDB('./db')# single putdb.Put('hello', 'world')print db.Ge……继续阅读 » 8年前 (2018-10-24) 3166浏览 288个赞
python没有像C++那样的函数指针,但是python提供了更为简洁方便的函数赋值方式def foo(): print "foo" f = foo f() ……继续阅读 » 8年前 (2018-10-24) 3022浏览 825个赞
Python 实现的插入法排序代码#-*- coding: utf-8 -*-# the insertation sort# 2012-07-29 noona = [3, 2, 4, 1, 5, 4, 2, 3, 6, 5, 7, 4, 1, 0]for j in range(1, len(a)): i = 0 while a[……继续阅读 » 8年前 (2018-10-24) 2794浏览 2813个赞
python修改文件名、目录名os.rename("/path/to/old/file", "/path/to/new/file") ……继续阅读 » 8年前 (2018-10-24) 4028浏览 1331个赞
下面列举了TextCtrl的可用样式'''wx.TE_CENTER:控件中的文本居中。wx.TE_LEFT:控件中的文本左对齐。默认行为。wx.TE_NOHIDESEL:文本始终高亮显示,只适用于Windows。wx.TE_PASSWORD:不显示所键入的文本,代替以星号显示。180 / 565wx.TE_PR……继续阅读 » 8年前 (2018-10-24) 3744浏览 495个赞
wxpython中的所有文本框都是TextCtrl,不同的形式的文本框通过样式来实现,下面创建了一个密码输入框pwdText = wx.TextCtrl(panel, -1, ”password”, size=(175, -1), style=wx.TE_PASSWORD)……继续阅读 » 8年前 (2018-10-24) 1609浏览 658个赞
wxpython的文本框可以在创建时设置样式,下面的例子给文本框设置为制度、富文本编辑、不自动换行等样式style = (wx.TE_MULTILINE | wx.TE_READONLY | wx.TE_RICH2 | wx.TE_DONTWRAP)wx.TextCtrl.__init__(self, parent, id, style=style)……继续阅读 » 8年前 (2018-10-24) 3411浏览 2751个赞
python在控制台输入密码但是不显示import console;namespace console{ //控制台读取密码,并显示星号 getPassword = function(){ var tstr = {}; var input = kbRead(true); while( i……继续阅读 » 8年前 (2018-10-24) 2966浏览 1404个赞
运行这段代码,将生成一个简单的左右结果的框架,非常好用,需要wx.aui模块# -*- coding: cp936 -*-# 2010-04-20 18:40 中国广州天河# 如何实现动态布局# source:http://stackoverflow.com/questions/523363/how-do-i-layout-a-3-pane-wi……继续阅读 » 8年前 (2018-10-24) 2107浏览 132个赞
wxpython自带一个列表选择对话框SingleChoiceDialog,可以用一个数组定义要选择的元素列表dlg = wx.SingleChoiceDialog(None,’What version of Python are you using?’, ’Single Choice’,[‘1.5.2’, ’2.0’, ’2.1.3’, ’2.2’,……继续阅读 » 8年前 (2018-10-24) 2557浏览 2434个赞
python实现的代码行数统计代码''' Author: liupengfei Function: count lines of code in a folder iterativelyShell-format: cmd [dir] Attention: default file encode ……继续阅读 » 8年前 (2018-10-24) 2148浏览 2827个赞
用go计算一个人的年龄,生肖,星座,输入参数为用户的出生年月日(类型string ,格式”2006-05-04″).package main import ( "fmt" "time") func GetTimeFromStrDate(date string) ……继续阅读 » 8年前 (2018-10-24) 2872浏览 1578个赞
JavaScript生成随机颜色var randomColor = Math.floor(Math.random()*16777215).toString(16); ……继续阅读 » 8年前 (2018-10-24) 2276浏览 1241个赞
怎么使用JavaScript让Textarea支持tab按键HTMLTextAreaElement.prototype.getCaretPosition = function () { //return the caret position of the textarea return this.selectionStart;};HTML……继续阅读 » 9年前 (2018-04-08) 2547浏览 493个赞
python过滤字符串中不属于指定集合的字符# -*- coding: utf-8 -*-import string# 生成所有字符的可复用的字符串,它还可以作为# 一个翻译表,指明“无须翻译”allchars = string.maketrans('', '')def makefilter(ke……继续阅读 » 9年前 (2018-01-22) 2517浏览 2166个赞
用Python提取url链接中的域名与端口import urllib proto, rest = urllib.splittype("http://www.75271.com/11/12.htm") host, rest = urllib.splithost(rest) print host host, port……继续阅读 » 9年前 (2018-01-21) 2909浏览 533个赞
冒泡法排序Go语言版func BubbleSort(nums []int) { unsorted := true for unsorted { unsorted = false for i := len(nums) - 1; i > 0; i-- { if nums[i……继续阅读 » 9年前 (2018-01-21) 2675浏览 2185个赞
go语言实现的简单http服务代码package mainimport ( "flag" "log" "net/http" "text/template")var addr = flag.String("addr&q……继续阅读 » 9年前 (2018-01-20) 3161浏览 2180个赞
go语言编写的猜数字的小游戏代码随机生成一个数字,输入一个数字看是否匹对,匹配则结速,反之提示是大了还是小了转自:http://www.waylau.compackage mainimport ( "bufio" "fmt" "math/rand" "os"……继续阅读 » 9年前 (2018-01-20) 3143浏览 758个赞
python自动修改本机网关的代码#!/usr/bin/python#auto change gateway Created By mickelfengimport osimport random,reg='gateway 192.168.1.'rand=random.randint(1,3)test='……继续阅读 » 9年前 (2018-01-20) 3315浏览 2449个赞
Go语言官方带了一个工具叫cgo,可以很方便的在Go语言代码中内嵌C代码或做C和Go代码的集成。下面是一段简单的在Go中内嵌C的实验代码:package main/*#include #include void say_hello() { printf("Hello World!\n");}*/……继续阅读 » 9年前 (2018-01-20) 3247浏览 293个赞
凡是线性回溯都可以归结为右递归的形式,也即是二叉树,因此对于只要求一个解的问题,采用右递归实现的程序要比回溯法要优美的多。def Test(queen,n): '''这个就不用说了吧,就是检验第n(下标,0-7)行皇后的位置是否合理''' q=queen[n] for i in xrange……继续阅读 » 9年前 (2018-01-20) 3437浏览 2353个赞
python检查序列seq 是否含有aset 中的项# -*- coding: utf-8 -*-def containsAny(seq, aset): """ 检查序列seq 是否含有aset 中的项 """ for c in seq: if c in ……继续阅读 » 9年前 (2018-01-20) 4819浏览 2549个赞
python十进制转二进制,可指定位数# convert a decimal (denary, base 10) integer to a binary string (base 2)# tested with Python24 vegaseat 6/1/2005def Denary2Binary(n): ''……继续阅读 » 9年前 (2018-01-20) 2605浏览 2736个赞
在python里面excel的简单读写操作我这里推荐使用xlrd(特别是读操作)到http://pypi.python.org/pypi/xlrd 去下载 xlrd库;import xlrd def open_excel(fileName="simple.xls"): try: fileH……继续阅读 » 9年前 (2018-01-20) 1901浏览 2063个赞
用Python实现二分查找#!/usr/bin/env pythonimport sys def search2(a,m): low = 0 high = len(a) - 1 while(low <= high): mid = (low + high)/2 midval ……继续阅读 » 9年前 (2018-01-20) 2202浏览 630个赞
一行代码实现python字符串反转输出import reastring = 'hello world'revchars = astring[::-1]print(revchars)输出结果dlrow olleh ……继续阅读 » 9年前 (2018-01-20) 3063浏览 1437个赞
你可能已经猜到 switch 可能的形式了。case 体会自动终止,除非用 fallthrough 语句作为结尾。package mainimport ( "fmt" "runtime")func main() { fmt.Print("Go runs on ") s……继续阅读 » 9年前 (2018-01-20) 2312浏览 221个赞
在这个练习中,将会使用 Go 的并发特性来并行执行 web 爬虫。修改 Crawl 函数来并行的抓取 URLs,并且保证不重复。package mainimport ( "fmt")type Fetcher interface { // Fetch 返回 URL 的 body 内容,并且将在这个页面上……继续阅读 » 9年前 (2018-01-20) 2815浏览 2120个赞
channel 是有类型的管道,可以用 channel 操作符 <- 对其发送或者接收值。ch <- v // 将 v 送入 channel ch。v := <-ch // 从 ch 接收,并且赋值给 v。(“箭头”就是数据流的方向。)和 map 与 slice 一样,channel 使用前必须创建:ch := make(chan……继续阅读 » 9年前 (2018-01-20) 3263浏览 1764个赞
Go语言for当做while用法演示package mainimport "fmt"func main() { sum := 0 for { sum ++ if sum > 10{ break }else{ fmt.Println(sum) } }} ……继续阅读 » 9年前 (2018-01-20) 3668浏览 2611个赞
Go语言单个文件拷贝演示代码package mainimport "fmt"import "io"import "os"func main(){ w,err := CopyFile("filecopy.go","test.go") i……继续阅读 » 9年前 (2018-01-20) 2356浏览 373个赞
读取源文件,去掉空行,并写到目标文件/** * Created with IntelliJ IDEA. * User: hyper-carrot * Date: 12-8-31 * Time: 下午4:04 * To change this template use File | Settings | File Templates.……继续阅读 » 9年前 (2018-01-20) 3240浏览 1104个赞
websockets的bufferedAmount使用范例代码// 10k max buffer size.var THRESHOLD = 10240; // Create a New WebSocket connectionvar ws = new WebSocket("ws://w3mentor.com"); ……继续阅读 » 9年前 (2018-01-20) 1877浏览 2741个赞
Go语言模仿linux cat命令package mainimport ( "io" "os" "fmt" "bufio" "flag")var numberFlag = flag.Bool("n"……继续阅读 » 9年前 (2018-01-20) 1819浏览 462个赞