2011年7月22日

摘要: 1.Python如何实现单例模式?参考答案:Python有两种方式可以实现单例模式,下面两个例子使用了不同的方式实现单例模式:1. 1 class Singleton(type): 2 def __init__(cls, name, bases, dict): 3 super(Singleton, cls).__init__(name, bases, dict) 4 cls.instance = None 5 def __call__(cls, *args, **kw): 6 if cls.instance is None: 7 cls.instance = super(Singleton, 阅读全文

posted @ 2011-07-22 15:30 仆本浪人 阅读(839) 评论(0) 推荐(0) 编辑

摘要: 1.有两个序列a,b,大小都为n,序列元素的值任意整形数,无序;要求:通过交换a,b中的元素,使[序列a元素的和]与[序列b元素的和]之间的差最小。参考答案: 1 # -*- coding: utf-8 -*- 2 #定义2个无序的整数列 3 a = [1,34,5,3,66,866,98,76] 4 b = [3,43,565,232,545,2,4,3] 5 #a b 的大小都是n 6 n = len(a) 7 #连接2个序列 8 c = a+b 9 #对新序列进行从小到大的排列10 c.sort()11 #从新取前面n个大小给a12 a = c[:n]13 #从新取后面n个大小给b14 阅读全文

posted @ 2011-07-22 15:24 仆本浪人 阅读(929) 评论(0) 推荐(0) 编辑

摘要: Python是如何进行内存管理的?http://developer.51cto.com/art/201007/213585.htm(没看懂)什么是lambda函数?它有什么好处?http://www.kuqin.com/diveinto_python_document/apihelper_lambda.html解释一下python的 and-or 语法http://www.kuqin.com/diveinto_python_document/apihelper_andor.htmlhow do I iterate over a sequence in reverse orderPython是如 阅读全文

posted @ 2011-07-22 15:08 仆本浪人 阅读(2452) 评论(0) 推荐(1) 编辑