2013年4月22日
摘要: 有两个列表A,BA = [[[3, 5], [0, 2], [2, 10]], [[6, 9], [7, 2], [9, 7]], [[3, 3], [5,3], [10, 2]]];B = [[0, 2], [2, 10], [3, 3]];如何得到[[0, 1, 1], [0, 0, 0], [1, 0, 0]]?求解:>>> A = [[[3, 5], [0, 2], [2, 10]], [[6, 9], [7, 2], [9, 7]], [[3, 3], [5, 3], [10, 2]]]>>> B = [[0, 2], [2, 10], [3, 3 阅读全文
posted @ 2013-04-22 21:53 101010 阅读(187) 评论(0) 推荐(0) 编辑
摘要: 比如:a = [1, 2, 4]输出3a = [1, 2, 3, 4, 8, 9, 12] 只输出5求解:>>> a = [1, 2, 3, 4, 8, 9, 12]>>> set(range(a[0],a[-1]+1))-set(a){10, 11, 5, 6, 7}>>> sorted(list(set(range(a[0],a[-1]+1))-set(a)))[5, 6, 7, 10, 11]>>> sorted(list(set(range(a[0], a[-1]+1)) - set(a)), reverse=Tr 阅读全文
posted @ 2013-04-22 21:33 101010 阅读(1624) 评论(0) 推荐(0) 编辑
摘要: 写个函数,把list1变成res,最好像Python的风格list1=[["a1","a2"],["b1","b2"],["c1","c2"],["d1","d2"]]res=[["a1", "a2"], ["a2", "b1"], ["b1", "b2"], ["b2", "c1&quo 阅读全文
posted @ 2013-04-22 21:12 101010 阅读(1734) 评论(0) 推荐(0) 编辑
摘要: 比如:[3,4,5,6,7,10,11,12,15,16,17,19,20,21,22,23,24,42,43,44,45,46,48]怎么得到下面的结果呢?[[3,7],[10,12],[15,17],[19,24],[42,46],[48,48]]解答代码:>>> a = [3,4,5,6,7,10,11,12,15,16,17,19,20,21,22,23,24,42,43,44,45,46,48]>>> t1 = []>>> t2 = []>>> for x in a: t1.append(x) if x+1 no 阅读全文
posted @ 2013-04-22 20:54 101010 阅读(1836) 评论(0) 推荐(0) 编辑
摘要: Java:http://docs.oracle.com/javase/http://docs.oracle.com/javase/7/docs/index.htmlhttps://tomcat.apache.org/tomcat-7.0-doc/index.htmlhttp://docs.oracle.com/javaee/http://docs.oracle.com/javaee/6/api/OpenJDK官网:http://openjdk.java.net/代码库:http://hg.openjdk.java.net/JDK7 update的代码仓库森林(repo forest),下面有h 阅读全文
posted @ 2013-04-22 17:25 101010 阅读(279) 评论(0) 推荐(0) 编辑
摘要: Python应用编程需要用到的针对不同数据库引擎的数据库接口:http://wiki.python.org/moin/DatabaseInterfacesPython标准的DB API 2.0见:http://www.python.org/dev/peps/pep-0249/本文将以SQLite和PySqlite为例来学习Python DB API。pysqlite是一个sqlite为python 提供的api接口,它让一切对于sqlit的操作都变得异常简单。从Python2.5起,pysqlite作为Python的一个标准模块。在使用标准库时,它被简称为sqlite3模块。sqlite3标准 阅读全文
posted @ 2013-04-22 16:01 101010 阅读(4263) 评论(0) 推荐(0) 编辑
  2013年4月19日
摘要: # 文件的基本方法以及对内容的迭代# 1.open,write and read>>> f = open(r'E:\code\py\file\test.txt','w')>>> f.write('hello, ')7>>> f.write('world')5>>> f.close()>>> f = open(r'E:\code\py\file\test.txt','r')>>> f.read( 阅读全文
posted @ 2013-04-19 19:06 101010 阅读(250) 评论(0) 推荐(0) 编辑
摘要: 一个简单模版系统的实现:# templates.pyimport fileinput, re# 定义用于匹配字段的模式field_pat = re.compile(r'\[(.+?)\]')# 创建充当模版作用域的字典:以字典形式收集变量scope = {}# 定义替换函数,用于re.sub中def replacement(match): # 返回模式中与给定子模式(组)匹配的子字符串 code = match.group(1) try: # 若字段可以求值(求表达式的值),则返回其值 return str(eval(code, scope)) ... 阅读全文
posted @ 2013-04-19 11:46 101010 阅读(394) 评论(0) 推荐(0) 编辑
  2013年4月18日
摘要: # 实现的功能如下:提示用户输入一个句子(英文,并且按enter键结尾),# 该程序将句子中的字母按ASCII码编码顺序重新排列,排列后的单词的长度要与原始句子中的长度相同,# 例如: 输入:who is your daddy,输出:add dh ioor suwyy s = input('please input a string:\n')# 先排序,去空格tmp_s = list(filter(lambda c : not c.isspace(), sorted(s, reverse = True)))print(tmp_s)# 再在原始串空格位置上插入空格,其他位置为排序 阅读全文
posted @ 2013-04-18 19:11 101010 阅读(413) 评论(0) 推荐(0) 编辑
摘要: Python offers two different primitive operations based on regular expressions:re.match() checks for a match only at the beginning of the string,while re.search() checks for a match anywhere in the string (this is what Perl does by default).For example:>>> re.match('a','abc') 阅读全文
posted @ 2013-04-18 17:23 101010 阅读(279) 评论(0) 推荐(0) 编辑