python
MyHuster
这个作者很懒,什么都没留下…
展开
-
python 学习笔记——列表(list)
序列相加:[1,2,3]+[4,5,6] 结果是:[1,2,3,4,5,6]原创 2014-10-31 17:09:17 · 620 阅读 · 0 评论 -
python 学习笔记——类
在函数前面加双下划线使函数为私有,私有类只有类的内部访问,实例不能访问私有函数,同样私有函数不能被继承函数的参数当参数有默认值时,该参数后面的所有参数都必须有默认值当父类实现了构造函数__init__()时,如果子类也要实现构造函数,则必须显示调用父类的构造函数:例如class Baseclass(): GLOBAL = None def __init原创 2015-01-19 23:28:10 · 536 阅读 · 0 评论 -
冒泡排序
# coding:utf-8__author__ = 'taohao'"""bubble sort"""def bubble_sort(array): i = j = 0 length = len(array) while i < length-1: while j < length-i-1: if array[j] >原创 2015-03-15 10:59:14 · 353 阅读 · 0 评论 -
堆排序以及二叉堆的一些操作
注意: 此文中的二叉堆默认为最小二叉堆此处的堆排序是降序排序原创 2015-03-15 16:47:44 · 461 阅读 · 0 评论 -
快速排序
def quick_sort(array, left, right): if left < right: # the if is necessary. only when left < right, the recursion can be handled i = left j = right tem = array[left]原创 2015-03-14 15:50:41 · 356 阅读 · 0 评论 -
shell 排序
# coding:utf-8__author__ = 'taohao'"""shell sort is improving the performance of the insert sort"""def shell_sort(array): gap = len(array)/2 while gap > 0: i = gap while原创 2015-03-14 18:35:45 · 478 阅读 · 0 评论 -
插入排序
# coding:utf-8__author__ = 'taohao'"""insert sort"""def insert_sort(array): i = 1 while i < len(array): tem = array[i] j = i while tem 0: array[j] =原创 2015-03-14 18:19:35 · 410 阅读 · 0 评论 -
归并排序
# coding:utf-8__author__ = 'taohao'""" merge sort use the extra space to exchange the time when merge two arrays, we need to use another empty array to store the completed array so the p原创 2015-03-14 17:12:20 · 435 阅读 · 0 评论 -
python学习笔记——列表推导 list comprehension
python 的列表推导的方式进行遍历,这样可以利用python 的特性加快遍历效率>>> numbers = range(10)>>> size = len(numbers)>>> evens = []>>> i = 0>>> while i < size:... if i % 2 == 0:... evens.append(i)...原创 2015-04-05 20:01:56 · 474 阅读 · 0 评论 -
Hadoop 分析图中节点的重要性,求解图中节点三角形个数
Hadoop 求解无向图中节点的重要性,通过求解节点的三角形个数来展现:求解图中节点重要性,并排序,在大数据,分布式处理大型图组织形式的数据时很重要,找出重要节点,并对重要节点做特殊处理是很重要的原创 2015-06-26 19:39:42 · 2027 阅读 · 0 评论 -
Hadoop 实现矩阵相乘
Hadoop 实现矩阵相乘包括两点:1、mapreduce实现矩阵相乘2、python脚本生成矩阵hadoop com.sun.tools.javac.Main MatrixMutiply.java jar cf matrix.jar MatrixMutiply*.classhadoop fs -rm -r /matrixoutput # 只是在再次运行时需要删掉上一次运行时生成的文件hadoop jar matrix.jar MatrixMutiply /matrixinput/*原创 2015-06-12 15:49:34 · 3959 阅读 · 3 评论 -
python 实现矩阵相乘
优势在于,矩阵的数据组织方式适合分布式计算# coding:utf-8__author__ = 'taohao'import randomclass Matrix(object): def build_matrix_a(self, row, col): """ matrix: 1 0 2原创 2015-06-12 16:01:01 · 2771 阅读 · 0 评论 -
tornado 使用supervisor管理进程,使用nginx做负载均衡
tornado 使用supervisor管理进程,使用nginx做负载均衡部署方式采用nginx作为load banlancernginx的配置文件如下,放在/etc/nginx/sites-avaiable/下,然后再sites-enable下面创建软连接nginx有一个基础配置会include sites-enable下的文件。以下代码是被配置的http{}部分所includeupstrea原创 2016-01-26 21:20:13 · 1840 阅读 · 0 评论 -
python 画心形线 matplotlib
心形线的数学表达式极坐标方程水平方向: r=a(1-cosθ) 或 r=a(1+cosθ) (a>0)垂直方向: r=a(1-sinθ) 或 r=a(1+sinθ) (a>0)直角坐标方程心形线的平面直角坐标系方程表达式分别为 x^2+y^2+a*x=a*sqrt(x^2+y^2) 和 x^2+y^2-a*x=a*sqrt(x^2+y^2)参数方原创 2015-06-25 18:48:18 · 30133 阅读 · 7 评论 -
python 学习笔记——python globals()
globals() : 将python的全局变量包括类,报名等全局属性封装在一个字典里面,key是属性名,value是属性值# coding:utf-8__author__ = 'taohao'a = set()class test1: def __init__(self): pass def a1(self): pass原创 2015-01-09 20:08:07 · 558 阅读 · 0 评论 -
python 学习笔记——getattr hasattr setattr delattr
getattr(obj,name) 获得一个属性值hasattr(obj,name) 判断是否有这个属性setattr(obj,name,value) 新增属性delattr(obj,name) 删一个属性class test(): def __init__(self): self.foo = 100a = test()setattr(a, 'a原创 2015-01-20 22:03:25 · 655 阅读 · 0 评论 -
python 学习笔记——元组(tuple)
只有一个值的元组:(42,) z原创 2014-10-31 18:08:48 · 618 阅读 · 0 评论 -
python 学习笔记 ——排序
list.sort() 没有返回值sorted(list) 返回一个排好序的里原创 2014-10-31 15:11:51 · 446 阅读 · 0 评论 -
Python socket 入门
import sockets = so第一个参数是指用的怎样的IP协议,这里AF_INET指IPV4 协议,第二个参数是指用的什么通信协议,SOCK_STREAM指TCP 协议,原创 2014-10-27 08:46:02 · 416 阅读 · 0 评论 -
python 学习笔记——字典(dict)
获取字典的keys:dict.keys() 返回一个元素是原创 2014-10-31 15:36:38 · 634 阅读 · 0 评论 -
python 学习笔记——set() class 集合类型
python的set和其他语言类似, 是一个无序不重复元素集, 基本功能包括关系测试和消除重复元素. 集合对象还支持union(联合), intersection(交), difference(差)和sysmmetric difference(对称差集)等数学运算.注意点:1、set类型是无序的2、set类型里面的元素是非重复的,即使在创建的时候的对象有重复元素,在创建se转载 2015-01-08 21:48:37 · 1384 阅读 · 0 评论 -
python 学习笔记——python 装饰器(三) @functools.wraps(0
def foo(): print "foo" print foo.__name__ #outputs: foo # With a decorator, it gets messy def bar(func): def wrapper(): print "bar" return func()原创 2015-01-11 15:25:57 · 564 阅读 · 0 评论 -
python 学习笔记——python 装饰器(二)
在stackoverflow上面看到一个关于Python中装饰器问题的回复,瞬间觉得作者简直是神人啊。原文地址:http://stackoverflow.com/questions/739654/how-can-i-make-a-chain-of-function-decorators-in-python这么好的一段东西,实在是忍不住拿过来翻译一下,有删改:转载 2015-01-11 15:14:03 · 644 阅读 · 0 评论 -
python 学习笔记——python 装饰器(一)
装饰器的作用:常见的用法可以用来扩展一个方法(这个方法是其他的库里面的,你没办法修改)也可以用来方便调试(你不想修改原来的方法,只是想暂时看一下调试信息,之后就删掉了)def benchmark(func): """ A decorator that prints the time a function takes to execute. 一个输出函数原创 2015-01-11 14:08:55 · 647 阅读 · 0 评论 -
python 学习笔记——参数 *args **kwargs
def a(*args,**kwargs): print args #args 表示的是所有的单个参数,包装成一个元组 print kwargs #kwargs 将所有的key=value 形式的参数包装成一个字典a(1,2,3,aa=4,bb=5) output:(1, 2, 3){'aa': 4, 'bb': 5}原创 2015-01-11 13:59:40 · 363 阅读 · 0 评论 -
python 学习笔记——try,except,else,finally
try: ##执行一些可能会引发异常的代码except: ##try语句中引发异常在这里被捕捉,执行此处的代码,这样不会在异常引发时导致程序执行中断else: ##如果try里面没有引发异常,执行此处的代码finally: ##不管try语句有没有引发异常,finally语句总是会被执行执行try下的语句,如果引发异常,则执行过程会跳到第一个except语句。◆如原创 2015-01-08 20:49:43 · 768 阅读 · 0 评论 -
python 学习笔记—— __setattr__ __getattr__ __str__
class Book(object): def __setattr__(self, name, value): if name == 'value': object.__setattr__(self, name, value - 100) else: object.__setattr__(self, name,原创 2015-01-11 22:41:52 · 483 阅读 · 0 评论 -
python 学习笔记——python metaclass 元类
译注:这是一篇在Stack overflow上很热的帖子。提问者自称已经掌握了有关Python OOP编程中的各种概念,但始终觉得元类(metaclass)难以理解。他知道这肯定和自省有关,但仍然觉得不太明白,希望大家可以给出一些实际的例子和代码片段以帮助理解,以及在什么情况下需要进行元编程。于是e-satis同学给出了神一般的回复,该回复获得了985点的赞同点数,更有人评论说这段回复应该加入原创 2015-01-11 22:23:55 · 738 阅读 · 0 评论 -
RabbitMQ工作模式详解
rabbitmq工作模式详解。工作队列发布订阅模式路由模式topic 模式本文会讲解工作队列,发布订阅模式,路由模式,topic模式 这四种工作模式。原创 2017-03-26 15:24:22 · 1747 阅读 · 0 评论