python challenge 学习
2016-07-03 15:44
239 查看
一直在自学python,但总是不知道如何更快的进步,直到偶然听说“python challenge”这个项目。
发现它不仅能锻炼自己的编程能力,更能使自己沉浸在解迷的快乐中。
凭借这些题目,能使自己保持良好的学习动力。
python challenge 第三题,利用正则找出特定格式的字符串,其中的小写字母就是下一题的线索:
python challenge 第四题,利用递归找出第五题的线索
python challenge 第五题,利用pickle还原对象得到下一题的线索
继续努力!!!
发现它不仅能锻炼自己的编程能力,更能使自己沉浸在解迷的快乐中。
凭借这些题目,能使自己保持良好的学习动力。
python challenge 第三题,利用正则找出特定格式的字符串,其中的小写字母就是下一题的线索:
import re regx = "[a-z]+[A-Z]{3}[a-z][A-Z]{3}[a-z]+" regx1 = "[A-Z]{3}[a-z][A-Z]{3}" s1 = "" cnt = 0 with open("pythonChallengeText4.txt") as fp: for eachline in fp.readlines(): temp = re.findall(regx,eachline) cnt += 1 if temp: print "[%d] %s"%(cnt,temp) for val in temp: for x in re.findall(regx1,val): s1 += x[3] print s1
python challenge 第四题,利用递归找出第五题的线索
# -*- coding:utf-8 -*- import urllib2,re,sys def getTheEnd(nums): site = "http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing="+nums page = urllib2.urlopen(site).read() if not re.search("\d+$",page): print "Done...%s"%site sys.exit(0) else: print "[%s] [%s] \n %s"%(nums,page,site) getTheEnd(page.split(' ')[-1]) if __name__ == '__main__': getTheEnd('83287')
python challenge 第五题,利用pickle还原对象得到下一题的线索
import pickle,urllib urllib.urlretrieve("http://www.pythonchallenge.com/pc/def/banner.p","banner.p") pickle.load(open("banner.p")) object = pickle.load(open("banner.p")) for item in object: print "".join(map(lambda p: p[0]*p[1], item))
继续努力!!!
相关文章推荐
- Python动态类型的学习---引用的理解
- Python3写爬虫(四)多线程实现数据爬取
- 垃圾邮件过滤器 python简单实现
- 下载并遍历 names.txt 文件,输出长度最长的回文人名。
- install and upgrade scrapy
- Scrapy的架构介绍
- Centos6 编译安装Python
- 使用Python生成Excel格式的图片
- 让Python文件也可以当bat文件运行
- [Python]推算数独
- Python中zip()函数用法举例
- Python中map()函数浅析
- Python将excel导入到mysql中
- Python在CAM软件Genesis2000中的应用
- 使用Shiboken为C++和Qt库创建Python绑定
- FREEBASIC 编译可被python调用的dll函数示例
- Python 七步捉虫法