摘抄
摘要:coded by 老鱼from itertools import combinations, productdef func(numbers, m, s): def determinate(args): return sum(args) == s return filter(determinate, product(numbers, repeat = m))print(func(range(10), 2, 5))输出: [(0, 5), (1, 4), (2, 3), (3, 2), (4, 1), (5, 0)]【 在 wenti (question) 的大作中提到: 】: n个数,任取m个
阅读全文
posted @
2012-09-18 10:37
fenix
阅读(113)
推荐(0)
temp
摘要:#coding=utf-8fromPILimportImageimportwin32apiimportwin32guiimportwin32uiimportwin32conimportmath_useless=[(237,237,237),(247,247,247)]_squareWidth,_squareHeight,_blocka=23,15,28.3_range=4#避免重复分的正方形版块大小_intervalConflict=600#3*3格内的点击相隔时间ms_interval=60#实际点击的时间间隔msdefColorComp(color1,color2):deltaR=abs(
阅读全文
数独
摘要:class SudokuCal: def __init__(self): self.str1 = '0' * 81 self.str2 = '0' * 81 self.answer = 0 self.done = False self.loop = 0 def same_row(self,i,j): return (i%9==j%9) def same_col(self,i,j): return (i-j)%9==0 def same_block(self,i,j): return (i%27%9/3==j%27%9/3) def print_format(se
阅读全文
posted @
2012-07-04 18:15
fenix
阅读(169)
推荐(0)
数字转中文读写....(参考别人后修改)
摘要:#coding=gbkimportreimportmathchinese_digits=(u'零',u'一',u'二',u'三',u'四',u'五',u'六',u'七',u'八',u'九')chinese_jinzhi=(u'万',u'',u'千',u'百',u'十',u'')wanindex=5defformatdigitwithjinzh
阅读全文
posted @
2010-02-05 15:11
fenix
阅读(294)
推荐(0)
各种排序
摘要:import randomimport datetimeimport copydef bubbleSort(data): l1 = len(data)-1 for i in xrange(l1,0,-1): for j in xrange(i): if(data[j]>data[j+1]): data[j],data[j+1] = data[j+1],data[j]def selectionSort(data): l = len(data) l1 = l-1 for i in xrange(l1):...
阅读全文
posted @
2009-06-09 17:41
fenix
阅读(240)
推荐(0)
Python模块--struct 数据格式转换
摘要:Python是一门非常简洁的语言,对于数据类型的表示,不像其他语言预定义了许多类型(如:在C#中,光整型就定义了8种),它只定义了六种基本类型:字符串,整数,浮点数,元组,列表,字典。通过这六种数据类型,我们可以完成大部分工作。但当Python需要通过网络与其他的平台进行交互的时候,必须考虑到将这些数据类型与其他平台或语言之间的类型进行互相转换问题。打个比方:C++写的客户端发送一个int型(4字节)变量的数据到 Python写的服务器,Python接收到表示这个整数的4个字节数据,怎么解析成Python认识的整数呢? Python的标准模块struct就用来解决这个问题。 struct模块.
阅读全文
posted @
2009-02-06 10:28
fenix
阅读(1121)
推荐(0)
filter, map, reduce, zip函数
摘要:1. filter(function, sequence) 返回序列,为原序列中能使function返回true的值 >>>a=[1,2,3,4] >>>filter(lambda x:x%2, a) [1, 3]2. map(function, sequence, [sequence...]) 返回序列,为对原序列每个元素分别调用function获得的值. 可以传入多个序列,但function也要有相应多的参数,如 map(lambda x,y,z:x+y+z,range(1,3),range(3,5),range(5,7)) 计算过程为 1+3+5=9
阅读全文
posted @
2008-06-18 09:15
fenix
阅读(194)
推荐(0)
schwartzian sort
摘要:#Timing test for "sort on fourth word"#Specifically,two lines>=4 words will be sorted#lexographically on the 4th,5th,etc..words#Any line with fewer than four words will sorted to # the end ,and will occur in "natural" orderimport sys,string,timewrerr = sys.stderr.write#native
阅读全文
posted @
2007-05-02 15:11
fenix
阅读(162)
推荐(0)