python检查序列seq 是否含有aset 中的项# -*- coding: utf-8 -*-def containsAny(seq, aset): """ 检查序列seq 是否含有aset 中的项 """ for c in seq: if c in ……继续阅读 » 8年前 (2018-01-20) 2016浏览 1633个赞
python十进制转二进制,可指定位数# convert a decimal (denary, base 10) integer to a binary string (base 2)# tested with Python24 vegaseat 6/1/2005def Denary2Binary(n): ''……继续阅读 » 8年前 (2018-01-20) 2263浏览 2088个赞
在python里面excel的简单读写操作我这里推荐使用xlrd(特别是读操作)到http://pypi.python.org/pypi/xlrd 去下载 xlrd库;import xlrd def open_excel(fileName="simple.xls"): try: fileH……继续阅读 » 8年前 (2018-01-20) 2416浏览 648个赞
用Python实现二分查找#!/usr/bin/env pythonimport sys def search2(a,m): low = 0 high = len(a) - 1 while(low <= high): mid = (low + high)/2 midval ……继续阅读 » 8年前 (2018-01-20) 1469浏览 2875个赞
一行代码实现python字符串反转输出import reastring = 'hello world'revchars = astring[::-1]print(revchars)输出结果dlrow olleh ……继续阅读 » 8年前 (2018-01-20) 2264浏览 215个赞
你可能已经猜到 switch 可能的形式了。case 体会自动终止,除非用 fallthrough 语句作为结尾。package mainimport ( "fmt" "runtime")func main() { fmt.Print("Go runs on ") s……继续阅读 » 8年前 (2018-01-20) 3135浏览 609个赞
在这个练习中,将会使用 Go 的并发特性来并行执行 web 爬虫。修改 Crawl 函数来并行的抓取 URLs,并且保证不重复。package mainimport ( "fmt")type Fetcher interface { // Fetch 返回 URL 的 body 内容,并且将在这个页面上……继续阅读 » 8年前 (2018-01-20) 1981浏览 1826个赞
channel 是有类型的管道,可以用 channel 操作符 <- 对其发送或者接收值。ch <- v // 将 v 送入 channel ch。v := <-ch // 从 ch 接收,并且赋值给 v。(“箭头”就是数据流的方向。)和 map 与 slice 一样,channel 使用前必须创建:ch := make(chan……继续阅读 » 8年前 (2018-01-20) 2010浏览 2605个赞
Go语言for当做while用法演示package mainimport "fmt"func main() { sum := 0 for { sum ++ if sum > 10{ break }else{ fmt.Println(sum) } }} ……继续阅读 » 8年前 (2018-01-20) 1567浏览 799个赞
Go语言单个文件拷贝演示代码package mainimport "fmt"import "io"import "os"func main(){ w,err := CopyFile("filecopy.go","test.go") i……继续阅读 » 8年前 (2018-01-20) 2243浏览 954个赞
读取源文件,去掉空行,并写到目标文件/** * Created with IntelliJ IDEA. * User: hyper-carrot * Date: 12-8-31 * Time: 下午4:04 * To change this template use File | Settings | File Templates.……继续阅读 » 8年前 (2018-01-20) 1455浏览 1046个赞
websockets的bufferedAmount使用范例代码// 10k max buffer size.var THRESHOLD = 10240; // Create a New WebSocket connectionvar ws = new WebSocket("ws://w3mentor.com"); ……继续阅读 » 8年前 (2018-01-20) 1735浏览 356个赞
Go语言模仿linux cat命令package mainimport ( "io" "os" "fmt" "bufio" "flag")var numberFlag = flag.Bool("n"……继续阅读 » 8年前 (2018-01-20) 2822浏览 2274个赞
python过滤字符串中不属于指定集合的字符的类# -*- coding: utf-8 -*-import setsclass Keeper(object): def __init__(self, keep): self.keep = sets.Set(map(ord, keep)) def __getitem……继续阅读 » 8年前 (2018-01-19) 2818浏览 2379个赞
可以通过easy_install qrcode 安装,也可以到:https://github.com/lincolnloop/python-qrcode 下载简单用法import qrcodeimg = qrcode.make('Some data here')高级用法import qrcodeqr = qrcode.……继续阅读 » 8年前 (2018-01-10) 1535浏览 2098个赞
使用一个循环,不断的创建线程,直到出现异常,才通知它们。python真是个好东西。#!/usr/bin/env python #coding=gbk import threading import time, random, sys class Counter: def __init__(self):……继续阅读 » 8年前 (2018-01-09) 3029浏览 844个赞
python实现的守护进程(Daemon)def createDaemon(): ”’Funzione che crea un demone per eseguire un determinato programma…”’ import os # create - fork 1 try: ……继续阅读 » 8年前 (2018-01-09) 2727浏览 532个赞
Perl批量执行Linux安装程序和脚本#!/usr/bin/perl#use Cwd;sub ExecuteAll(){ local($dir) = @_; opendir(DIR,"$dir"|| die "can't open $dir"); local @files =rea……继续阅读 » 8年前 (2018-01-09) 3023浏览 1110个赞
python提取url中的域名和端口号import urllib proto, rest = urllib.splittype("http://www.75271.com/11/12.htm") host, rest = urllib.splithost(rest) print host host, port =……继续阅读 » 8年前 (2018-01-09) 1983浏览 1962个赞
来源:http://blog.csdn.net/sun7545526/article/details/8138603需求:设计一个”石头,剪子,布”游戏,有时又叫”Rochambeau”,你小时候可能玩过,下面是规则.你和你的对手,在同一时间做出特定的手势,必须是下面一种手势:石头,剪子,布.胜利者从下面的……继续阅读 » 8年前 (2018-01-09) 1570浏览 2996个赞
python检查一个集合是否包含了另外一个集合的所有项>>> L1 = [1, 2, 3, 3]>>> L2 = [1, 2, 3, 4]>>> set(L1).difference(L2)set([ ])>>> set(L2).difference(L1)set(……继续阅读 » 8年前 (2018-01-09) 2293浏览 1529个赞
python字符串按单词反转输出方法1import reastring = 'hello world'revwords = ' '.join(reversed(astring.split()))print(revwords)方法2import reastring = 'hello ……继续阅读 » 8年前 (2018-01-09) 3108浏览 1282个赞
python通过正则获取网页上的全部链接import re, urllibhtmlSource = urllib.urlopen("http://www.75271.com").read(200000)linksList = re.findall('<a href="(.*?)">.*?……继续阅读 » 8年前 (2018-01-09) 1613浏览 1466个赞
程序会监听8080端口,然后简单的返回web/路径下的文件,假如只输入类似localhost:8080,会自动找到index.htmlpackage mainimport ( "net/http")func main() { http.Handle("/", http.FileServ……继续阅读 » 8年前 (2018-01-09) 2827浏览 1382个赞
Python获取CPU使用率、内存使用率、网络使用状态注:需要安装psutil库#!/usr/bin/env python## $Id: iotop.py 1160 2011-10-14 18:50:36Z g.rodola@gmail.com $## Copyright (c) 2009, Jay Loden, Giampaolo Ro……继续阅读 » 8年前 (2018-01-08) 1525浏览 1119个赞
python通过代理服务器访问ftp服务import urllib2# Install proxy support for urllib2proxy_info = { 'host' : 'proxy.myisp.com', 'port' : 3128, ……继续阅读 » 8年前 (2017-07-11) 2620浏览 2930个赞
python3 压缩文件夹内的文件到zip'''Created on Dec 24, 2012将文件归档到zip文件,并从zip文件中读取数据@author: liury_lab'''# 压缩成zip文件from zipfile import * #@UnusedWil……继续阅读 » 8年前 (2017-07-11) 1427浏览 1070个赞
/** 密码发生器 在对银行账户等重要权限设置密码的时候,我们常常遇到这样的烦恼:如果为了好记用生日吧,* 容易被破解,不安全;如果设置不好记的密码,又担心自己也会忘记;如果写在纸上,担心纸张被别人发现或弄丢了…* 这个程序的任务就是把一串拼音字母转换为6位数字(密码)。* 我们可以使用任何好记的拼音串(比如名字,王喜明,就写:wangx……继续阅读 » 8年前 (2017-07-11) 3080浏览 793个赞
python返回指定日期是一年中的第几周>>> import datetime>>> print datetime.datetime(2006,9,4).isocalendar()[1]36 ……继续阅读 » 8年前 (2017-07-11) 2036浏览 171个赞
golang日志记录库简单使用方法范例package mainimport ( "fmt" "log" "os")func main(){ logfile,err := os.OpenFile("/var/golang/75271.com.log",……继续阅读 » 8年前 (2017-07-04) 2517浏览 791个赞
asp.net将DataGrid控件中的数据导出Execl提供下载System.Web.UI.Control ctl=this.DataGrid1;//DataGrid1是你在窗体中拖放的控件HttpContext.Current.Response.AppendHeader("Content-Disposition","……继续阅读 » 8年前 (2017-07-04) 3155浏览 1412个赞
d157e0d7f137c9ffc8d65473e038ee86 是 “Hello world !” 使用 “mykey”作为key的签名结果>>> import hmac>>> print hmac.new("mykey","Hello ……继续阅读 » 8年前 (2017-07-04) 1426浏览 1304个赞
本代码运行后会减轻8088端口,用户访问:http://127.0.0.1:8088 或输出html代码:Hello World!#!/usr/bin/pythonimport BaseHTTPServerclass MyHandler(BaseHTTPServer.BaseHTTPRequestHandler): def do_GET(……继续阅读 » 8年前 (2017-07-04) 3038浏览 1551个赞
python读取文件同时输出行号和内容file = open('file.txt','r')for (num,value) in enumerate(file): print "line number",num,"is:",valuefile.close()……继续阅读 » 8年前 (2017-07-03) 2012浏览 323个赞
python实现简单的soap客户端# $Id: testquote.py 2924 2006-11-19 22:24:22Z fredrik $# delayed stock quote demo (www.xmethods.com)from elementsoap.ElementSOAP import *class QuoteService……继续阅读 » 8年前 (2017-07-03) 2265浏览 869个赞
python 递归搜索文件夹下的指定文件import osdef look_in_directory(directory): """Loop through the current directory for the file, if the current item is a directory……继续阅读 » 8年前 (2017-07-03) 1970浏览 1514个赞
python读取LDIF文件#!/usr/bin/python# -*- coding: iso-8859-1 -*-import ldif # ldif module from http://python-ldap.sourceforge.netclass testParser(ldif.LDIFParser): def __in……继续阅读 » 8年前 (2017-06-15) 1714浏览 1224个赞
python获取一组数据里的最大值max函数使用演示# 最简单的max(1, 2)max('a', 'b')# 也可以对列表和元组使用max([1,2])max((1,2))# 还可以指定comparator functionmax('ah', 'bf……继续阅读 » 8年前 (2017-06-15) 2742浏览 1203个赞
zip可以对元组进行元素对应重组,返回一个新的元组数组>>> print zip( ['a','b','c'], [1,2,3] )[('a', 1), ('b', 2), ('c', 3)]>>&g……继续阅读 » 8年前 (2017-06-15) 2440浏览 1616个赞
如果你有一个表格,想把行和列进行互换,这段python代码帮你实现,超简单table = [ ('Person', 'Disks', 'Books'), ('Zoe' , 12, 24 ), ('……继续阅读 » 8年前 (2017-06-09) 1473浏览 634个赞
Java求1000以内的水仙花数打印出所有的 “水仙花数 “,所谓 “水仙花数 “是指一个三位数,其各位数字立方和等于该数本身。例如:153是一个 “水仙花数 “,因为153=1的三次方+5的三次方+3的三次方。public class 水仙花数 { public static v……继续阅读 » 8年前 (2017-06-09) 2784浏览 2514个赞
本代码从 sebsauvage.net 读取RSS2.0文档,并对其进行分析并显示全部标题import urllib, sys, xml.dom.minidomaddress = 'http://www.75271.com.net/rss/updates.xml'document = xml.dom.minidom.parse(……继续阅读 » 8年前 (2017-06-09) 1865浏览 1748个赞
金明今天很开心,家里购置的新房就要领钥匙了,新房里有一间他自己专用的很宽敞的房间。更让他高兴的是,妈妈昨天对他说:“你的房间需要购买哪些物品,怎么布置,你说了算,只要不超过N 元钱就行”。今天一早金明就开始做预算,但是他想买的东西太多了,肯定会超过妈妈限定的N 元。于是,他把每件物品规定了一个重要度,分为5 等:用整数1~5 表示,第5 等最重要。他还从因特……继续阅读 » 8年前 (2017-06-09) 2972浏览 485个赞
字符串编辑距离 这是一种字符串之间相似度计算的方法。 给定字符串S、T,将S转换T所需要的插入、删除、替代操作的数量叫做S到T的编辑路径。 其中最短的路径叫做编辑距离。 这里使用了一种动态规划的思想求编辑距离。package com.mycompany.project;/** * 字符串编辑距离 * * 这是一种字符串之间相似度计算的方法……继续阅读 » 8年前 (2017-06-04) 3124浏览 2350个赞
先说一下大致思路,然后贴代码,之后分析代码中的各个函数,实现充分展现了Tutu_Lux扎实的基本功和灵动的脑瓜子,哈,:-) 。思路:由于N是从3至9的范围,解决方案就是针对每个N的取值,先计算三个分隔符“_ + -”填入序列1-N的所有可能组合的情况总数设置所有情况的组合序列(采用3进制的思想,即set函数)对每种组合计算表达式值,如果为0则输出(利用栈&……继续阅读 » 8年前 (2017-06-01) 1289浏览 2810个赞