随笔分类 -  Python

python 中初始化二维数组的方法
摘要:最好的方法是:初始化4*3的二维数组a = [[0 for col in xrange(3)] for row in xrange(4)]而不可以用:a = [[0]*3]*4[0]*3是生成一个一维数组,再*4只是会复制出三个引用,当修改a[0][0]时,其他的三个引用的值也会发生改变,故这种方法... 阅读全文

posted @ 2014-07-25 23:52 Stomach_ache 阅读(655) 评论(0) 推荐(0) 编辑

Python sorted
摘要:sorted函数:iterable:是可迭代类型;cmp:用于比较的函数,比较什么由key决定,有默认值,迭代集合中的一项;key:用列表元素的某个属性和函数进行作为关键字,有默认值,迭代集合中的一项;reverse:排序规则. reverse = True 或者 reverse = False,有... 阅读全文

posted @ 2014-05-17 19:29 Stomach_ache 阅读(229) 评论(0) 推荐(0) 编辑

python中defaultdict类
摘要:回宿舍前翻翻Codeforces的时候发现了一个有趣的代码..其实是我没这么用过 :D这是一份417B的代码 1 import sys 2 from collections import defaultdict 3 4 n = int(sys.stdin.readline()) 5 d = def... 阅读全文

posted @ 2014-05-13 23:18 Stomach_ache 阅读(183) 评论(0) 推荐(0) 编辑

hackerrank---Sets - Symmetric Difference
摘要:题目链接集合操作附上代码:1 M = int(input())2 m = set(map(int, raw_input().strip().split()))3 N = int(input())4 n = set(map(int, raw_input().strip().split()))5 tmp... 阅读全文

posted @ 2014-05-11 17:17 Stomach_ache 阅读(143) 评论(0) 推荐(0) 编辑

hackerrank---Find a string
摘要:题目链接在字符串a中查找字符串b出现的次数...貌似不可以用a.count()附上代码:1 a = raw_input().strip()2 b = raw_input().strip()3 cnt = 0;4 for i in xrange(len(a)):5 cnt += 1 if a.... 阅读全文

posted @ 2014-05-11 16:53 Stomach_ache 阅读(167) 评论(0) 推荐(0) 编辑

hackerrank---List Comprehensions
摘要:题目链接刷刷Python基本功...列表解析附上代码:1 x = int(input())2 y = int(input())3 z = int(input())4 n = int(input())5 print [[i, j, k] for i in xrange(x+1) for j in xr... 阅读全文

posted @ 2014-05-11 16:29 Stomach_ache 阅读(189) 评论(0) 推荐(0) 编辑

Python比较有用的小语法
摘要:额,这是在Codeforces做题的时候从Virtual judge那儿学的#ord()内置函数,将单个字符变为int#chr()内置函数,将int变为单个字符# for : else ( 或 while : else) 这个语法好用 阅读全文

posted @ 2014-03-28 22:04 Stomach_ache 阅读(152) 评论(0) 推荐(0) 编辑

Python 中的 map, reduce, zip, filter, lambda基本使用方法
摘要:map(function, sequence[, sequence, ...]该函数是对sequence中的每个成员调用一次function函数,如果参数有多个,则对每个sequence中对应的元素调用function。返回值为一个列表如: def func(x): return x + 10; ... 阅读全文

posted @ 2014-02-27 12:26 Stomach_ache 阅读(181) 评论(0) 推荐(0) 编辑

python中bisect模块的使用
摘要:一般用于二分查找, 当然列表应该是有序表参考于:http://blog.csdn.net/xiaocaiju/article/details/6975714 阅读全文

posted @ 2014-02-16 14:19 Stomach_ache 阅读(117) 评论(0) 推荐(0) 编辑

初次接触python的re模块
摘要:刷CF的时候,看到一个简单的题目,可以用来练练正则表达式于是乎找到了re.sub的用法,说明如下re.sub: (pattern, repl, string, count=0, │ flags=0) │ Return the string obtained by replacing the left... 阅读全文

posted @ 2014-01-07 10:13 Stomach_ache 阅读(154) 评论(0) 推荐(0) 编辑

zoj 1001 python起步
摘要:1 /*赶角还是挺好的。。。。*/2 import sys3 4 for line in sys.stdin:5 a=line.split()6 print int(a[0])+int(a[1]) 阅读全文

posted @ 2013-07-12 21:05 Stomach_ache 阅读(188) 评论(0) 推荐(0) 编辑

The Zen of Python
摘要: 阅读全文

posted @ 2013-07-11 15:08 Stomach_ache 阅读(112) 评论(0) 推荐(0) 编辑

导航

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