pythonchallenge 挑戰筆記

poplarbbs發表於2008-11-04
Level 1 :
學習了string.translate() 和string.maketrans()
核心程式碼:
string.translate(oldstr, string.maketrans(old, new))


Level 2 :
學習了isalpha(),但這只是一種取巧的思路,我覺得一般還是用改用字典型別來實現

Level 3 :
學習了re.findall()。返回的是正則中括號部分組成的list
核心程式碼:
re.findall('[a-z][A-Z]{3}([a-z])[A-Z]{3}[a-z]', a)


Level 4 :
學習了re 和 urllib 模組。這裡很奇怪的用re.match()會得到None
核心程式碼:

filehandle = urllib.urlopen("http://www.pythonchallenge.com/pc/def\/linkedlist.php?nothing=%s" % nothing, None)
page = filehandle.read()
filehandle.close()
nothing = re.findall("\d+", page, re.MULTILINE)[0]

相關文章