- 博客(7)
- 收藏
- 关注
原创 网络爬虫入门
import urllib.request;import re; url = "http://news.xinhuanet.com/politics/2015-12/20/c_128549058.htm";data = urllib.request.urlopen(url);# 返回对象,有各种方法txt = data.read().decode("utf-8","ignore"); #
2015-12-20 21:16:17 422
原创 正则表达式入门
import re;txt = "this is a good thing, that is a bad thing";rule1 = ["this", "that", "a"];p = list( re.compile(p) for p in rule1 );for i, r in enumerate(p): print( i, r ); for x in r.finditer
2015-12-13 22:03:39 349
原创 括号套括号的计数
def count(tar, a): tot,tar= 0,str(tar); for v in a: if type(v) == type([]): #判定是否有嵌套 tot += count(tar, v); else: tot += (tar == str(v)); return tot;
2015-12-06 21:58:02 703
原创 字符串快速过滤
keep = "1 2 3 4 5 6 7 8 9 0".split();a = "adfh23aks4j5dh234fe3412uiw1\n!";# lazy filternew_a = "".join(ch for ch in a if ch in keep);
2015-12-06 21:54:20 499
原创 逐行快速读入
f = open("output.txt","w");# lazy readlinefor line in open("lx.txt"): f.write(line);f.close();
2015-11-29 22:27:22 366
原创 魔性的 turtle 入门
#3 Hello Turtlesimport turtlesc = turtle.Screen();sc.bgcolor("lightgreen") sc.title("Hello World");ai = turtle.Turtle();ai.color("pink");ai.shape("turtle");ai.pensize(5);ai.speed(0); #
2015-11-29 22:24:43 444
原创 ASCII 与 Int
# ord() char -> ASCII # chr() ASCII -> chardef toint( ch ): ch = str( c h); # from hex to dec etc if( ch >= '0' and ch return int( ch ); else: return 10 +
2015-11-22 22:19:40 681
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人