随笔分类 -  python编程

python装饰器小例子
摘要:in the test1the func run time 3.0043931007385254in the test2 joan 5the func run time 2.0034029483795166 阅读全文

posted @ 2017-07-02 21:13 joangaga 阅读(339) 评论(0) 推荐(0) 编辑

递归返回指定文件夹中文件的路径,以及其包含文件夹中文件的路径
摘要:import osdef print_directory_contents(sPath): for sChild in os.listdir(sPath): sChildPath = os.path.join(sPath,sChild) if os.path.isdir(sChildPath): p 阅读全文

posted @ 2017-07-02 20:39 joangaga 阅读(307) 评论(0) 推荐(0) 编辑

分别使用shell和python实现两列排序
摘要:有一个文件1.txt如下,要求使用shell和python实现排序,先按照第一列排序,第一列相同再按照第二列排序,并且输出到另外一个文件2.txt LZdeMacBook-Pro:~ lz$ cat 1.txt 23 d 26 t 12 y 43 h 5 k 12 a shell实现: LZdeMa 阅读全文

posted @ 2017-06-28 11:19 joangaga 阅读(1230) 评论(0) 推荐(0) 编辑

python 实现二叉树 求二叉树的叶子节点个数
摘要:#coding=utf-8class Node(object): """节点类""" def __init__(self, elem=-1, lchild=None, rchild=None): self.elem = elem self.lchild = lchild self.rchild = 阅读全文

posted @ 2017-06-22 18:27 joangaga 阅读(5088) 评论(1) 推荐(0) 编辑

python实现简单爬虫程序
摘要:#coding=utf-8import reimport urllib def getHtml(url): page = urllib.urlopen(url) html = page.read() return html def getImg(html): reg = r'src="(.*?\.j 阅读全文

posted @ 2017-04-26 15:51 joangaga 阅读(267) 评论(0) 推荐(0) 编辑

python 列表排序
摘要:转自http://www.iplaypython.com/jinjie/jj114.html reverse()方法 将列表中元素反转排序,比如下面这样>>> x = [1,5,2,3,4]>>> x.reverse()>>> x[4, 3, 2, 5, 1]reverse列表反转排序:是把原列表中 阅读全文

posted @ 2016-08-12 17:48 joangaga 阅读(5039) 评论(0) 推荐(0) 编辑

python实现排序算法
摘要:冒泡排序 import randomdef BubbleSort(num): n=len(num) for i in range(0,n): for j in range(i,n): if num[i]>=num[j]: num[i],num[j]=num[j],num[i] return num 阅读全文

posted @ 2016-08-12 09:46 joangaga 阅读(241) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示